
How to pass data to multiple partial view files in laravel
How to pass data to multiple partial view files in laravel
We’ll attempt to use programming in this lesson to solve the "How to pass data to multiple partial view files in laravel" puzzle.
You can pass data to multiple partial view files in laravel using appserviceprovider. it returns the data to the specified view files in which you want to show data.-
Pass data to multiple partial view files using AppServiceProvider in laravel
//app\Providers\AppServiceProvider.php public function boot(){ \View::composer(['partials/right_sidebar', 'partials/left_sidebar'], function ($view) { $user = DB::table('users')->select('id','name','email','image')->first(); $view->with(['user'=>$user]); }); } //resources\views\partials\left_sidebar.blade.php {{ $user->name }} //resources\views\partials\right_sidebar.blade.php {{ $user->name }}
This code snippet will return the user detail to both left_sidebar and right_sidebar partial view file. You just have to create the file right_sidebar and left_sidebar in resources\views\partials\ directory and display data using the $user variable.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Target class [HomeController] does not exist
- How to get query string value in laravel
- How to create project_user pivot table in laravel
- There are no commands defined in the "route:" namespace
- Json encode method in laravel
- How to pass query string to url in laravel
- How to check record exist or not in relationship table
- Remove array keys and values if it does not exist in other array in Laravel
- Ignore Records where a field has NULL value in Laravel
- Insert Comma Separated Values in laravel
- How to validate URL with https using regex in laravel
- Get only 10 records from table in laravel
- How to get records in random order in laravel
- How to pass two variables in HREF in laravel
- Include External CSS and JS file in Laravel
- Laravel pagination links with query string
- Save or update pivot table data with additional column in Laravel
- Get today records in Laravel
- Laravel delete all rows older than 30 days
- Update record after find method in lavavel
- Laravel onclick function not working
- Route prefix with auth middleware in laravel
- Laravel create default admin user
- Trying to access array offset on value of type null error in laravel
- How to make Copy or Duplicate table row in laravel