1

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.

3 Answers 3

3

You can use following...

return View::make('index', compact('Posts', 'image'));
Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

I worked at a PHP role for several years where the convention was to capitalise object variables, lower-case for everything else. Took me ages to unlearn it ;-).
Yeah, right now I'm learning Python. and I'm a PHP Developer. It is really hard to not use the braces for functions and classes. because I'm a PHP Developer.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.