Home > Blockchain >  take user id in all views with laravel
take user id in all views with laravel

Time:06-01

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 >
{{dd($comprador)}}
    </div>

and this is the final result enter image description here

CodePudding user response:

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 >
  {{ auth()->user() }}
</div>

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

CodePudding user response:

    
    
    
    
    
    userlistviewpage.php
    
    <table >

    <thead>

      <th>Username</th>

      <th>Orders</th>

      <th>Balance</th>

    </thead>

    <tbody>
@foreach($users as $user)

        <tr>

          <td>{{$user->username}} </td>

          <td>{{$user->purchases}} </td>

          <td>{{$user->balance}} </td>


        </tr>
@endforeach

    </tbody>

</table>

    Controller.php:

    public function boot() {
       $comprador = User::all();

        return view('profile.userlistviewpage', compact('users'));
        
        }

  • Related