4
good morning! I followed what is said in this tutorial to fill values in a view: https://www.tutorialspoint.com/laravel/retrieve_records.htm
And I did the same scheme on my controller:
public function select_cursos_disciplinas()
{
$cursos = DB::table('select * from cursos');
$disciplinas = DB::table('select * from disciplinas');
return view('cadastros.disciplinas_curso', ['cursos' => $cursos, 'disciplinas' => $disciplinas]);
}
In my view it’s like this:
<select class="form-control">
<option disabled selected> --- </option>
@if ($cursos)
@foreach ($cursos as $curso)
<option> {{ $curso->nome }} </option>
@endforeach
@endif
</select>
However, it is giving the error "Trying to get Property of non-object". I already researched but I did not find the solution to what I need, because the solution was for only one value, but in my case I want several values.
What should I do to fill my select? Thank you
Thanks for the help Gumball. But it still gave the same error :/. I’m reading the log here and it seems that this DB returns an object of type stdClass. Does it have anything to do?
– WitnessTruth
Haaa, truth. Put a
->get()
at the end of the method. I will edit my code.– Diego Souza
@Virgilionovic you could maybe give a timely time to give these kinds of comments. I already had that in mind and when I have a time I edit the answer.
– Diego Souza
Thanks. It worked. However, I had to change the string inside the table only to the table name, otherwise it would be an error. But you’ve already kicked the solution.
– WitnessTruth