In my web.php I have the following route set up. What I was wanting to know is there something specific that I need to follow to get a sub domain of a sub domain to work?
The domain I am using is blah.blah.domain.tld
web.php:
Route::group(['domain' => '{blah}.blah.domain.tld'], function (){
Route::get('', 'DealsFrontEnd#index' );
});
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class DealsFrontEnd extends Controller
{
public function index()
{
return view('front.deals');
}
}
Too long for a comment: Try using a closure for debugging:
Route::group(['domain' => '{blah}.blah.domain.tld'], function (){
Route::get('', function() {
echo "Hello World";
});
});
Make sure you have debug enabled to make use of Laravel's error handling/reporting.
As I said in the comments, you shouldn't wrap the subdomain in brackets unless you want it to be dynamic.
{blah}.blah means it will capture anything.blah and the route variable $blah will be equal to anything.
Related
I wanna redirect to my controller instead of a view but it says: "Target class [app/Http/Controllers/MyFirstController] does not exist. "
here is the code (web.php file):
//just a view
Route::get('/', function () {
return view('index');
});
//just a view
Route::get('/final', function () {
return view('welcome');
});
//the controller is interested in
Route::get('/hello-controller', 'app/Http/Controllers/MyFirstController#index');
Controller code (app/Http/controllers/MyFirstController.php) :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MyFirstController extends Controller
{
public function index(){
return "viva";
}
}
additional information:
Laravel Framework version: 8.83.17
PHP version : PHP 7.4.29
The namespace is not correct: Capital A for App and use \ instead of /
Route::get('/hello-controller', 'App\Http\Controllers\MyFirstController#index');
or even better :
Route::get('/hello-controller', [\App\Http\Controllers\MyFirstController::class, 'index']);
try to clear cache your controller by using
php artisan route:cache
and also maybe u should use
//the controller is interested in
Route::get('/hello-controller', 'App/Http/Controllers/MyFirstController#index');
im still new to laravel 8 and i have a problem that says the target class does not exist. i believe it have something with the route of some sorts(?) im not sure. i only follow the tutorial but this is the error that i get. this is what i wrote,
web.php:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::group(['middleware' => ['auth', 'admin']], function () {
Route::get('/dashboard', function () {
return view('admin.dashboard');
});
Route::get('/role-register','Admin\DashboardController#registered');
});
Ensure the class App\Http\Controllers\Admin\DashboardController exists at the correct location with the correct namespace at the top of the file. This should be in app/Http/Controllers/Admin/ with the namespace App\Http\Controllers\Admin.
For consistency, use [App\Http\Controllers\Admin\DashboardController::class, 'registered'] instead of 'Admin\DashboardController#registered' when referencing the controller method. You might want to name this route too.
Try using the following.
Route::get('/role-register',
[App\Http\Controllers\Admin\DashboardController::class, 'registered']);
Instead of:
Route::get('/role-register', 'Admin\DashboardController#registered');
Use the correct namespace i.e
'namespace'=>'App\Http\Controllers\Admin' instead of 'namespace'=>'Admin'.
How can I access a subfolder controller on resource Route?
I have this structure of folders:
-Controllers
--Superadmin
---PermissionController.php
PermissionController.php
<?php
namespace App\Http\Controllers\Superadmin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PermissionController extends Controller
{
}
I have tried some ways for this but still get the same error Target class was PermissionController was not found.
web.php
Route::group(['middleware' => 'auth'], function() {
Route::resource('permission', 'Superadmin\PermissionController'); // 1
Route::resource('permission', 'PermissionController'); // 2
Route::resource('permission', App\Http\Controllers\Superadmin\PermissionController::class); //3
Route::resource('permission', PermissionController::class); //4
)}
Here are all the solutions I have tried. I also added the use App\Http\Controllers\Superadmin\PermissionCotnroller when I tried solution number 4. Can't find the problem.
Try adding the namespace parameter to the group, like so:
Route::group(['namespace'=>'Superadmin','middleware'=>'auth'], function () {
Route::resource('permission', 'PermissionController'); // 2
}
I have multiple URLs going to a single Laravel application:
www.mydomain.com
panel.mydomain.com
Within this I have several routes configured:
<?php
Route::group(['middleware' => ['web']], function () {
Route::get('/page', 'App\MyApp\Page\Controllers\PageController#index')->name('home');
});
Route::group(['middleware' => ['web'], 'domain' => 'panel.mydomain.com'], function() {
Route::get('/page', 'App\MyApp\Page\Controllers\ControlPanelPageController#index')->name('controlpanel.dashboard');
});
So anyone going on panel.mydomain.com gets a ControlPanelPageController index method, everyone else gets the PageController method.
However I'm having difficulty generating a link from a named route.
For example:
<?php
namespace App\MyApp\Page\Controllers;
use App\Http\Controllers\Controller;
class ControlPanelPageController extends Controller
{
public function index()
{
echo route('home');
// output: /page
echo url( route('home') );
// output: panel.mydomain.com/page
// required output: www.mydomain.com/page
}
}
I am new in Laravel. I am trying to create a new page named as "contact". But i am getting a Object not found error when i am trying to access the contact page
URL: project-name/contact
please help me
---routes file
<?php
Route::get('/','WelcomeController#index');
Route::get('contact','WelcomeController#contact');
Route::group(['middleware' => ['web']], function () {
//
});
--- Welcome controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class WelcomeController extends Controller
{
public function index(){
return view('welcome');
}
public function contact(){
return 'Contact page goes here...';
}
}
Set your home directory to the public to make things work.
Exchange the route. like this:
Route::get('contact','WelcomeController#contact');
Route::get('/','WelcomeController#index');