Search code examples
facebooklaravel-5laravel-bladelaravel-viewslaravel-controller

How to pass a variable to two different view from a controller in Laravel


I am working on developing a social networking site.

In my view folder there are two different folders:

1.layout: Layout have app.blade file: This file contain an notification header like fb. example: Notification example Image

2.user : User have home.blade file: it is contain home view.

Now when any user logs in it goes to home view first,Home view fecthing data from home controller Like this :

return view('home',compact('data','postblog');

But I also want to show a notification in notification section of app.blade file. So, My question is how can I send the data to that view too along with home view?

If you know any other way of doing this, please guide me.


Solution

  • app.blade.php can access your data directly. don't need extra options as mentioned above by Ray Cheng.

    Or you can do that using view composer method For more : https://laravel.com/docs/5.4/views