The Route-Model bound instance should be available using $this->route('dynamicPage')
Apr 21, 2023
5
Level 1
Variable in Request is allways empty
I have checked the code several times now and just can't find my error. With three other models everything works as desired.
My route
Route::resource('dynamic-pages', DynamicPageController::class)->except('show');
My form in the edit.blade.php
<form method="POST" action="{{ route('backend.dynamic-pages.update', [$dynamicPage->id]) }}" id="dynamicPageForm">
@method('PUT')
@csrf
My edit and update statement in the controller
public function edit(DynamicPage $dynamicPage)
{
$dynamicPage->with('translations');
return view('dynamic-pages.edit')->with([
'dynamicPage' => $dynamicPage,
]);
}
public function update(DynamicPageRequest $request, DynamicPage $dynamicPage)
{
$dynamicPage->update($request->validated());
//......
}
And my DynamicPageRequest file
class DynamicPageRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
if (!empty($this->dynamicPage->id)) $dynamicPageId = $this->dynamicPage->id;
else $dynamicPageId = null;
dd($dynamicPageId, $this->dynamicPages);
//.....
}
}
$this->dynamicPage is always empty. But why?
Level 104
@KodaC what is the wildcard parameter for the route; dynamicPage or dynamic_page? I wonder if Route Model binding is working at all?
public function update(DynamicPageRequest $request, DynamicPage $dynamic_page)
Then in the Request:
$this->route('dynamic_page')
1 like
Please or to participate in this conversation.