How to send several functions from different controllers to a view in laravel

0

I have a view where I want to load several data from different tables, I have them in different controllers, how can I send that data through a route to the view.

Route::get('estudiantes',function(){
return view('estudiantes');})->name('estudiantes');

This is the route with which I enter the view

    
asked by Jeisson Hernandez 12.01.2018 в 17:47
source

2 answers

0

The data that you want to send to a view must be in a method, example:

public function index(){
    $data1 = Model1::all();
    $data2 = Model2::all();
    return view('estudiantes', [
       'data1' => $data1,
       'data2' => $data2,
    ]);

}

Path, File web.php

  

Route :: get ('students', 'StudentsController @ index') - > name ('students');

    
answered by 12.01.2018 в 18:08
0

As I understand you need to get data from several models in a controller.

For this we simply call the model using the namespace of said model.

For example

public function index(){
    $ciudades = \App\Ciudades::get();
    $departamentos = \App\Departamentos::get();

        return view('estudiantes', [
           'ciudades' => $ciudades,
           'departamentos' => $departamentos,
        ]);
}
    
answered by 15.01.2018 в 14:39