Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

take user id in all views with laravel

first sorry for my english cuz im from spain.
ok the problem is when i try to get the user in all views with appserviceprovider, this is my code

    public function boot() {
   $comprador =Auth::user();

    View::share('comprador', $comprador);}

and next i try to get the item in other view and the result is null

   <div class="col-6 ">
{{dd($comprador)}}
    </div>

and this is the final result
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You dont need to declare any variables you have the auth global helper that you can use anywhere. The code in your blade looks like this.

<div class="col-6 ">
  {{ auth()->user() }}
</div>

if you need lets say the name of the user its just auth()->user()->name etc.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading