i have a form with single input. this single input name is callsign and should unique in table and my model name is callsign also in the table column name is callsign.
when i am trying to get callsign model object with this->callsign for retrieving id but it return form name callsign like test. actually i want to update with unique validation and ID need id for this.
public function update(UpdateRequest $request, Callsign $callsign)
{
dd($request->validated());
}
request code:
public function prepareForValidation(): void
{
$user_id = auth()->user()->id;
dd($this->id);
// replace the data ready for validation
$this->merge([
'user_id' => $user_id,
]);
}
@Snapey yes!
i solved it. its strange for i change the form input name callsign to callsign_name then calling the model object of callsign it received with ID.
thanks @snapey
I had the same issue in a Resource Controller. Model binded variable was empty in Edit and Update methods:
// web.php
Route::resource('medias', MediaGroupController::class);
// MediaGroupController.php
public function update(Request $request, MediaGroup $media)
{
// $media is an empty instance of MediaGroup.
}
The name of model binded variable must be media_group and not media.
To change the name of variable you must specify it in the route's parameters:
// web.php
Route::resource('medias', MediaGroupController::class, ['parameters' => [
'media' => 'media_group' //implicit binding type-hinted variable
]]);
// MediaGroupController.php
public function update(Request $request, MediaGroup $media)
{
// Now $media was binded to the right model instance
}