I'm getting an error when I try to pass data from the controller to the view and I spent a lot of time trying to solve it. The error is "Undefined Variable $instEntNacs". There is other form this view, because depending on the rol, it will show the first or the second one.
Here's the controller "ConvenioController":
public function create()
{
$instEntNacs = DB::table('inst_ent_nacs')->select('id', 'nombre')->get();
return view('convenios.create', ['instEntNacs' => $instEntNacs]);
}
And the view:
@if (auth()->user()->rol_id == "2")
<form method="POST" action="{{ route('convenios.store_nac') }}" enctype="multipart/form-data">
@csrf
<div >
<div >
<select id="con_instEntNac" name="con_instEntNac">
<option selected value="">-- Institución o Entidad --</option>
@foreach ($instEntNacs as $item)
<option value="{{ $item->id }}"> {{ $item->nombre }}</option>
@endforeach
</select>
</div>
</div>
<div >
<div >
<a href="{{ route('login.activites') }}">Regresar</a>
</div>
<div >
<button type="submit" >Cancelar</button>
</div>
<div >
<button type="submit" >Registrar</button>
</div>
</div>
</form>
@endif
CodePudding user response:
Have you tried this?
$data['instEntNacs'] = DB::table('inst_ent_nacs')->select('id', 'nombre')->get();
return view('convenios.create')->with($data);
CodePudding user response:
You can tried compact('instEntNacs') with return view('convenios.create).