I am trying to store data for my form but i keep getting
App\Http\Controllers\KeyresultController::store(): Argument #2 ($objective) must be of type App\Models\Objective, string given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54
here is my store function inside KeyresultController.php
public function store(Request $request, Objective $objective)
{
//
$objective = Objective::where('id',$objective->id)->first();
$request->validate([
'keyresult_name' => 'required',
]);
keyresult::create([
'keyresult_name' => $request->keyresult_name,
'keyresult_details' => $request->keyresult_details,
'progress' => $request->progress
]);
Deadline::create([
'date' => $request->date,
'until' => $request->until,
]);
return redirect('/sistem/monitor/objective/details/{team}/{objective}')->with('status', 'keyresult and new Keyresult Successfully Added');
}
here my form from new_keyresult.balde.php :
<form method="POST" action="{{route('sistem.monitor.objective.details', [$team->id, $objective->id])}}">
@csrf
<div class="form-group row">
<label for="newkeyresult" class="col-md-4 col-form-label text-md-right">Keyresult</label>
<div class="col-md-6">
<input type="text" id=newkeyresult name="keyresult_name" class="form-control @error ('keyresult_name') is-invalid @enderror">
@error('keyresult_name')
<div class="invalid-feedback">
{{ $message }}
</div>
@enderror
</div>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<a href="/sistem/monitor/objective/details/{{ $team->id }}/{{ $objective->id }}"><input type="button" class="btn btn-danger" value="Cancel"></a>
</div>
</div>
</form>
and here is my routing :
Route::get('/sistem/monitor/keyresult/new/{team}/{objective}', 'KeyresultController@create');
Route::post('/sistem/monitor/objective/details/{team}/{objective}', 'KeyresultController@store')
Change route to
Route::get('/sistem/monitor/keyresult/new/{team}/{objective}', [KeyresultController::class,'create']);
Route::post('/sistem/monitor/objective/details/{team}/{objective}', [KeyresultController::class],'store')
Ref:https://laravel.com/docs/8.x/routing#the-default-route-files
And also in store method param you have
public function store(Request $request, Objective $objective)
But as per route you have param team
and objective
so
public function store(Request $request,$team, Objective $objective)