Saturday, March 18, 2017

How to work with Views without using PHP's "compact" function in LARAVEL

I'm working on laravel to fetch data from database and store that data or array of data into the variable like $tasks store data of tasks table from database up till everything is fine but during processing the $task variable it is necessary to use "compact" function ?

And can anyone explain this

Route::get('/test', function () {

$data   =   [
                'name'  =>  'Vrushal',
                'last'  =>  'Raut',
                'tasks' =>  [
                                'Programming',
                                'UI/UX Developement',
                                'Cloud Expert'
                            ]
            ];
            //return view('templates/test', compact($data)); //NOT WORKING
            //return view('templates/test', $data); // ITS WORKING
            return View::make('templates/test',$data); // ITS WORKING
}); 

As well as with Database plz explain this

Route::get('/tasks', function(){

$tasks  =   DB::table('tasks')->get();

return view('templates/tasks', compact('tasks')); // ITS WORKING
//return View::make('templates/test',$tasks); // NOT WORKING
});

Thanks in Advance!



via Vrushal Raut

Advertisement