Reputation: 11
After 'php artisan make:controller Admin/DashboardController', I included code below (Controllers/Admin/DashboardController).
DashboardController.php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class DashboardController extends Controller
{
//Dashboard
public function dashboard(){
return view('admin.dashboard');
}
}
In web.php:
Route::get(['prefix'=>'admin', 'namespace'=>'Admin', 'middleware'=> ['auth']], function() {
Route::get('/', 'DashboardController@dashboard')->name(admin.index);
});
In views/admin/dashboard.blade.php
@extends('layouts.app)
@section('content')
<h1>Admin test</h1>
@endsection
Upvotes: 0
Views: 4143
Reputation: 35190
Whereas the other answers and comments are right admin.index
should be 'admin.index'
, the issue here is because you have a get()
route inside another get()
route.
If you want to nest routes like this you should use Route::group(...)
(not get()
):
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => ['auth']], function () {
Route::get('/', 'DashboardController@dashboard')->name('admin.index');
});
Upvotes: 1
Reputation: 14278
Your route name is not a string, so try this:
Route::get('/', 'DashboardController@dashboard')->name('index');
You will again access it as route('admin.index')
Upvotes: 1