Laravel - Pass more than one variable to view

前端 未结 11 1591
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 18:54

I have this site and one of its pages creates a simple list of people from the database. I need to add one specific person to a variable I can access.

How do I modif

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 19:31

    with function and single parameters:

        $ms = Person::where('name', 'Foo Bar');
        $persons = Person::order_by('list_order', 'ASC')->get();
        return $view->with(compact('ms', 'persons'));
    

    with function and array parameter:

        $ms = Person::where('name', 'Foo Bar');
        $persons = Person::order_by('list_order', 'ASC')->get();
        $array = ['ms' => $ms, 'persons' => $persons];
        return $view->with($array);
    

提交回复
热议问题