problem loading 2 select with data in Laravel 5.6.7?

1

I have a problem filling out two different selections within the same form in laravel 5.6.7.

vista: registro.blade.php

<div class="form-group">
   {{ Form::label('empresa','Empresa:',['class' => 'control-label  ']) }                                    
      <select class="form-control">
          @foreach($empresas as $empresa)
             <option value="{{$empresa->id}}">{{$empresa->nombre}}</option>
          @endforeach
      </select>                  
 </div>

<div class="form-group">
 {{ Form::label('modalidad','Modalidad:',['class' => 'control-label  ']) }}

  <select class="form-control">
      @foreach($modalidades as $modalidad)
         <option value="{{$modalidad->id}}"> 
             {{$modalidad->nombre_modalidad}}
         </option>
      @endforeach
 </select>
</div>

route: web.php

   Route::get('cursos/guardar', ['as' => 'registro',
                               'uses' => 'CursosController@selectEmpresas']);

   Route::get('cursos/guardar', ['as' => 'registro',
                               'uses' => 'CursosController@selectModalidades']);

Controller: CursosController.php

    public function selectEmpresas(Request $request)
    {
        $empresas = Empresa::all();
        return view('cursos.registro',compact('empresas'));//

    }

    public function selectModalidades()
    {
        $modalidades = Modalidad::all();
        return view('cursos.registro',compact('modalidades'));
    }

When I charge the two select I get the following error:

  

'Undefined variable: companies (View:   C: \ xampp \ htdocs \ project-laravel \ resources \ views \ courses \ registry.blade.php) ',

This error appears when I load the two select at the same time, since I tried to load only the company select and it brings me the names of the companies loaded in the table of the database, after this test, comment on the company code and I tried to bring me only a select in this case modality and it brings me perfectly the data of the modalities table, the error only comes out when I charge the two select together. (I hope you understand), I would appreciate it if you could help me as I have fumed the google engine.

    
asked by Cesar 08.03.2018 в 21:18
source

2 answers

1

I solved the problem, what I did was to unify the two calls to the functions that were in the controller, in a single function and to bring me two fixes (data from two independent tables). The route stayed like this:

Route::get('cursos/guardar', ['as' => 'registro',
                             'uses' => 'CursosController@LlenadoSelect']);                               

and the driver stayed like this:

 public function LlenadoSelect()
{
    $empresas = Empresa::all();
    $modalidades = Modalidad::all();
    return view('cursos.registro',compact('empresas','modalidades'));
}

:)

    
answered by 08.03.2018 в 23:10
0
     $empresa=empresa::pluck('nombre','id');
     $modalidad=tienda::pluck('nombre_modalidad','id');
     return view('controlador.create',compact('empresa','modalidad')); 

So you take the steps that I need to select.

    
answered by 06.10.2018 в 00:10