将多个变量传递给laravel中的视图?

I retrieved those from the database and assigned them to variables, but i am not able to pass both of them to the view.

$Posts = posts::find($id);

$image = images::find($id);

I tried passing them both in an array but haven't had luck. tried this as well

return View::make('Index',['x_var' => $Posts, 'y_var' => $image]);

In the view it can only recognise the x_var and when i use the y_var the page crashes.

You can use following...

return View::make('index', compact('Posts', 'image'));

Or put it in a array like that..

$data = array(
   'Posts'  => posts::find($id),
   'image'   => images::find($id),
);

return View::make('Index')->with($data);

Edit

If you get an error with the y_var maybe there is a problem with the image you want to find. Please give us more information about the error.

There are two ways you can do this:

The first way:

return View::make('view', ['Posts' => $posts, 'image', $image]);

And the second way, Which is for me, is much cleaner:

return View::make('view', compact('Posts', 'image'));

And please be consistent when you're coding.

It's really annoying to see a variable capitalized.