Laravel - Pass more than one variable to view

前端 未结 11 1566
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  隐瞒了意图╮
    2020-11-29 19:41

    Passing multiple variables to a Laravel view

    //Passing variable to view using compact method    
    $var1=value1;
    $var2=value2;
    $var3=value3;
    return view('viewName', compact('var1','var2','var3'));
    
    //Passing variable to view using with Method
    return view('viewName')->with(['var1'=>value1,'var2'=>value2,'var3'=>'value3']);
    
    //Passing variable to view using Associative Array
    return view('viewName', ['var1'=>value1,'var2'=>value2,'var3'=>value3]);
    

    Read here about Passing Data to Views in Laravel

提交回复
热议问题