Where in Laravel does not return information

Asked

Viewed 137 times

-1

In my Professionalcontroller.php file, I have the code:

public function vinculo($id)
{
    $profissional = Profissional::find($id);
    $unidades = Unidade::all();
    $vinculos = Vinculo::where('profissional_id', '=', $id);

    return view('profissionais.vinculo', compact('profissional', 'unidades', 'vinculos'));
}

It returns the professional fields and units. However the links are not listed.

My link.blade.php file where the links should appear:

@foreach($vinculos as $vinculo)
    <tr>
        <td>{{$vinculo->vinculo}}</td>
        <td>{{$vinculo->cargo}}</td>
        <td>{{$vinculo->funcao}}</td>
        <td>{{$vinculo->horario}}</td>
        <td>
            <a href="{{route('vinculos.edit', $vinculo->id)}}"><i class="glyphicon glyphicon-pencil"></i></a>
            <a href="{{route('vinculos.remove', $vinculo->id)}}"><i class="glyphicon glyphicon-trash"></i></a>
            <a href="{{route('vinculos.show', $vinculo->id)}}"><i class="glyphicon glyphicon-zoom-in"></i></a>
        </td>                                
    </tr>                         
@endforeach

1 answer

1


do this:

$vinculos = Vinculo::where('profissional_id', '=', $id)->get();

->get() works to say that you have finished building your query and want to "get"/run to fetch the results.

Serves to make different validations in some cases, ex:

$query = $items = Item::take(10)
   ->orderBy('id', 'DESC')
   ->limit(10)
   ->with('categorias');

if ($user->isAdmin) {
    $query->where('type', '=', 'admin')
}

return $query->get();

In the example no matter the order you define the query, its mounting will only occur when the get() method is executed.

I hope it helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.