Language

How To Pass More Than One Variable to View In Laravel 5.4

Date 12 Aug, 2017

Details :

1. You can pass more than one variable to laravel view using two ways.

(a) First by using with() helper

(b) Second by using compact() function

1. with().helper

     public function index()
     {
                 $postdata = DB::table('posts')->get();
                 $postdata  =  json_decode( json_encode($postdata), true);
                 $vdata = DB::table('videos')->get();
                 $vdata  =  json_decode( json_encode($vdata), true);
                 return view('FrontEnd.index')->with(['postdata'=>$postdata,'vdata'=>$vdata]);
    
     }

2. compact() function

     public function index()
     {
                 $postdata = DB::table('posts')->get();
                 $postdata  =  json_decode( json_encode($postdata), true);
                 $vdata = DB::table('videos')->get();
                 $vdata  =  json_decode( json_encode($vdata), true);
                 return view('FrontEnd.index', compact('vdata', 'postdata'));
    
     }