fightstarr20
fightstarr20

Reputation: 12568

Laravel get Images in Show User Template

I am trying to make my images table accessable from /users/show.blade.php. I have this in my controlller..

public function show($id) 
{

     /* Get All CSCS Images For User */
     $my_images= Image::all(); 

    /* Get User From ID */
    $user = User::find($id);

    /* Return View */
    return view('users.show')->with('user', $user)->with('images', $my_images); 
}

When I try and use the $my_images variable in my template I get an undefined variable error for $my_images

Where am I going wrong?

Upvotes: 1

Views: 52

Answers (1)

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

You should try this:

public function show($id) 
{

     /* Get All CSCS Images For User */
     $my_images= Image::all(); 

    /* Get User From ID */
    $user = User::find($id);

    /* Return View */
    return view('users.show',compact('user','my_images')); 
}

You pass $my_images name as image in your blade file for getting this error.

Upvotes: 2

Related Questions