Brijpal Sharma
laravel
Publish on:-March 27th, 2019 ,
Category:- Web Development
Brijpal Sharma
laravel
Publish on:-March 27th, 2019 ,
Category:- Web Development
Many projects need dynamic nav bar where the user needs dynamic data in the navigation bar when any new data, should be shown in the navigation bar. so in this blog post, we learn how to create dynamic navigation in Laravel
laravel new navigation
After successful install Laravel Application, we move to the next step.
We required some data to show on navigation bar so insert dummy data.
Here we call some data using model and pass into all view so we can print that data in the whole project view.
<?php
namespace App\Providers;
use App\User;
use View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
//
}
public function boot()
{
Schema::defaultStringLength(191);
View::composer('*', function($view)
{
$allUser= User::all();
$view->with('allUser', $allUser);
});
}
}
Here we use the User table to show all user record in the navigation bar.
this is an easy part where we show data in the blade page.
@foreach ($allUser as $item)
<p>{{$item->name}} </p>
@endforeach
So here we completed the tutorial on how to create dynamic navigation in Laravel.
Thank you...
Brijpal Sharma
Hello, My Name is Brijpal Sharma. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of Codermen. I started this blog to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers...
You must be logged in to post a comment.