Abdallah Sakre
Abdallah Sakre

Reputation: 915

(Return view) is returning a limited number of variables

I'm simply trying to return three variables as shown below. I'm receiving an undefined variable: udraft which is the third variable. If I make them only two variables, it will work. Is there some limitation here?

return view('tabs', ['post' => $posts]  , ['acc' => $acc_usrs] , ['udraft' => $usr_draft]);

Upvotes: 0

Views: 46

Answers (3)

user9079355
user9079355

Reputation:

you can use compact

return view('tabs', compact('posts','acc_usrs','usr_draft'));

Upvotes: 1

Andrea Campana
Andrea Campana

Reputation: 46

As stated in the Laravel Documentation, here, you should pass an array of data, not a single array for each variable. Your code should be something like: return view('tabs', ['post' => $posts, 'acc' => $acc_usrs, 'udraft' => $usr_draft]);

Or use the ->with() method as mentioned in the documentation above.

Upvotes: 2

nakov
nakov

Reputation: 14288

Why not returning one array like this:

return view('tabs', [
    'post'   => $posts,
    'acc'    => $acc_usrs,
    'udraft' => $usr_draft
]);

Upvotes: 1

Related Questions