Hi I'm trying to use Route Model Binding using Route::resource(..) but when I try to return the model it is return as empty array []. Here is my route :
Route::resource('application','ApplicationController');
and from the view index.blade.php I successfully show all the data and linked them to to edit.blade.php like this :
@foreach ($appVersions as $appVersion)
<tr>
{{-- Type AppVersion --}}
<td>{{ $appVersion->type }}</td>
{{-- Message Alert --}}
<td>{{ $appVersion->alert }}</td>
{{-- Version --}}
<td>{{ $appVersion->version }}</td>
{{-- Link --}}
<td>{{ $appVersion->link }}</td>
{{-- Plaform --}}
<td>{{ $appVersion->platform }}</td>
{{-- Action --}}
<td><a class="glyphicon glyphicon-pencil cursor-hand" href="{{ route('application.edit',$appVersion) }}"></a></td>
</tr>
@endforeach
So I try to test to pass the model to edit page as you can see above route('application.edit',$appVersion) and try to directly return the model from the controller, this is my ApplicationController :
public function index()
{ //index fucntion to shows all the data appVersion
try{
// $data['appVersion'] = AppVersion::all();
$appVersion = AppVersion::find(1);
return view('application.index', compact('appVersion'));
}catch(\Illuminate\Database\QueryException $e){
return response()
->json([
'status'=>'failed',
'status_code'=>500,
'message' => 'An unexpected error has occurred on the server. Please contact server administrator.'
], 500);
}
}
public function edit(AppVersion $appVersion)
{//edit function to showing edit page
// if I return $appVersion here it will return [].
$type = ['Major'=>2, 'Minor'=>1];
return view('application.edit',compact('appVersion','type'));
}
so I've read the documentation about Route Model Binding but it is only showing the sample using the specific route like GET.
I've seen and checked neontsunami project it uses Route::resource(...) for Route Model Binding. I'm kinda lost here, and try to figure and where did I miss ?
NOTE : I'm using laravel 5.2