I am unable to display the items called in my show function. Anyone know why nothing is showing?
The Route :
$router->get('/contrats/{id}', [
'as' => 'contrats.show', 'uses' => 'ContratController@show'
]);
My public function show() :
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show(Contrat $contrat)
{
return view('show', compact('contrat'));
}
The View part :
<p><strong>Contrat n° :</strong> {{ $contrat->id }}</p>
<hr>
<p><strong>Type d'énergie :</strong> {{ $contrat->enrgy }}</p>
<hr>
<p><strong>Numéro gsrn :</strong> {{ $contrat->gsrn }}</p>
<hr>
<p><strong>Durée du contrat : {{ $contrat->duration }} mois</strong></p>
<hr>
<p><strong>Code promotionnel utilisé :</strong> {{ $contrat->codePromo }}</p>
I think the route should be
$router->get('/contrats/{contrat}', [...])
for route model binding to work.
Another possibility is to manually query the model.
$router->get('/contrats/{id}', [...])
public function show($id)
{
$contrat = Contrat::findOrFail($id);
return view('show', compact('contrat'));
}
This seems to be the approach used in the official Lumen framework documentation