
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
- How to get all posts which contains comments in laravel
- If condition in Laravel 9
- Attempt to read property "avatar" on null in Laravel
- Post model with title and body in laravel 8
- Laravel delete all rows older than 30 days
- How to get user information using hootlex/laravel-friendships package in laravel
- Skip first n record and display rest records in laravel view
- Update record after find method in lavavel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- Ajax GET request in laravel
- Laravel route parameter
- Touch parent updated_at in Laravel
- Send id with route Laravel
- Create project table with model and migration
- Display option of select as selected with blade directive Laravel
- Order by multiple columns in Laravel
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- Non-static method App\Http\Helper::myFunction() should not be called statically
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- JQuery each loop on json response after ajax in laravel
- The POST method is not supported for this route. Supported methods: PUT.
- Get content from web URL in laravel
- Calculate age from date of birth in Laravel
- Pass value from controller to model in laravel
- Add a subselect based on relationship using withAggregate method