From previous post now its time to add menus in our layout. But before that we need to create Profile and Frame Width controllers with index() method so that these can be linked in menu with appropriate routes.
Step 01: Making profile and frame width controller with artisan command
php artisan make:controller ProfileController php artisan make:controller FrameWidthController
Step 02: Now adding index() method in both the controller and populating the method with relevant eloquent query code. Please note during our seeding step we also have created models for profile and frame width as well as other resources.
// ProfileController.php // at the top use App\Models\Profile; // public function index( Request $request ) { $meta_title = 'All Profiles'; $query = Profile::query(); $profiles = $query->orderBy( 'id', 'desc' )->paginate( 10 )->withQueryString(); return view( 'profiles.list', compact( 'meta_title','profiles' ) ); } // FrameWidthController.php // at the top use App\Models\FrameWidth; // public function index( Request $request ) { $meta_title = 'All Frame Widths'; $query = FrameWidth::query(); $fw_widths = $query->orderBy( 'id', 'desc' )->paginate( 10 )->withQueryString(); return view( 'fw_widths.list', compact( 'meta_title','fw_widths' ) ); }
Step 03: Now adding relevant index() view blade file under corresponding resources/view folder
// list.blade.php under profiles folder @extends('layouts.app') @section('content') <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <table class="table mt-3"> <h2>Profiles</h2> <thead class="table-dark"> <tr> <th>Name</th> <th class="text-center">Id</th> <th class="text-center">Name</th> <th class="text-center">Cost</th> <th class="text-center">Created</th> <th class="text-center">Order</th> <th class="text-center">Actions</th> </tr> </thead> <tbody> <tr> <td>Denton Bruce</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> </tr> </tbody> </table> </div> </div> </div> @endsection // list.blade.php under fw_widths folder @extends('layouts.app') @section('content') <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <h2>Frame Widths</h2> <table class="table mt-3"> <thead class="table-dark"> <tr> <th class="text-center">Id</th> <th class="text-center">Number of items</th> <th class="text-center">Company</th> <th class="text-center">Phone no</th> <th class="text-center">job no</th> <th class="text-center">Email sent?</th> <th class="text-center">Created</th> <th class="text-center">Actions</th> </tr> </thead> <tbody> <tr> <td>Denton Bruce</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> <td class="text-center">demo</td> </tr> </tbody> </table> </div> </div> </div> @endsection
Step 04: Lastly, back in layouts/app.blade.php after li element of register link we can add these following li elements with corresponding links
<li class="nav-item"> <a class="nav-link" href="{{ route('users.index') }}">{{ __('Users') }}</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ route('products.index') }}">{{ __('Products') }}</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ route('profiles.index') }}">{{ __('Profile') }}</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ route('frame_widths.index') }}">{{ __('Frame Width') }}</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ route('orders.index') }}">{{ __('Orders') }}</a> </li>
Now in our localhost browser if we refresh it we will see all these menus are getting listed without any route errors. Please also note since we have used these routes under auth middleware these links are not accessible unauthorized.