
How to pass data to multiple partial view files in laravel
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.
Answers 1
-
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 }}
0This 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.
Random Code Snippet Queries: Laravel
- Drop foreign key column in Laravel using migration
- Method Illuminate\Events\Dispatcher::fire does not exist
- How to get user information using hootlex/laravel-friendships package in laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- Permission denied error while creating storage link in Laravel
- Extra Filter Query on Relationships in Laravel
- Laravel order by date not working
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Display message with session flash using bootstrap alert class in laravel
- Ajax GET request in laravel
- Generate unique username in Laravel
- How to pass two variables in HREF in laravel
- How to check email is valid or not in Laravel
- How to avoid duplicate entries in pivot table in Laravel
- Array to string conversion laravel Controller
- Validation for multiple forms on same page in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- Illuminate\Database\QueryException could not find driver
- How to display validation error in laravel
- How to check find method executed successfully in laravel
- How to return error message from controller to view in laravel
- Define variable and use in Laravel controller method
- Insert dummy data in users table Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- JQuery each loop on json response after ajax in laravel