laravel newbie- syntax for making/setting variable in view with a function in the controller

I’ve started my first project in laravel (following along with the beginner laracasts series). I’ve successfully made a ‘joggers’ scope and get_joggers() function in the controller to pass that set of data to a view- great!

So now- I have a view where I pass all the people, and a partial to show different subsets of them, like so:

@include ('partials._people_list', ['person_group' => $joggers]);

My question: On a view page, what’s the syntax declare/set a variable to the results of a function in the controller? I would imagine something like this, but since a view page wants HTML I’d at least have to put it in some php tags or something (though there’s probably a better way):
$person_group = action('<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c5c69637c60694f6362787e636060697e4c6b6978">[email protected]</a>_joggers');

This seems so painfully basic, but the first 27 laracasts didn’t get there and I’ve been hunting around for while. Thanks in advance for any help!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Update! I talked to a buddy at work, and the answer was to make/set $joggers in the PeopleController, and then pass it all along like so:

public function index()
{
    $people = Person::latest('created_at')
        ->displayable()
        ->orderBy('last', 'asc', 'first', 'asc')
        ->get();

    $joggers= Person::joggers('created_at')->get();

return view('person.index', compact('people', 'joggers'));

I’ve returned different types of data before, and it hadn’t occurred to me that I could send two different collections of people. Mystery solved 🙂


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x