Where in Laravel does not return information

-1

In my ProfessionalProtroller.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 fields and professional fields. But the links are not listed.

My link.blade.php file where 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
    
asked by anonymous 04.09.2018 / 15:06

1 answer

1

do this:

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

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

It serves to make different validations in some cases, eg:

$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 that does not matter the order you set the query, its assembly will only occur when the get () method is executed.

I hope you have helped.

    
04.09.2018 / 15:08