Reputation: 315
In custom GroupRequest in rules() I can get id of Group (that's the Model name) by $this->group->id.
public function rules()
{
if ($this->method() == 'PATCH') {
return [
'name' => 'required|min:2|max:255|unique:groups,name,'.$this->group->id,
];
} else {
return [
'name' => 'required|min:2|max:255|unique:groups',
];
}
}
How can I do it in custom ArticleCategoryRequest... in rules() but id of ArticleCategory (that's the Model name)...
$this->articlecategory->id don't work.
Upvotes: 0
Views: 113
Reputation: 2080
It depends on the route variable you used.
If you declared your route like this :
Route::patch('article-categories/{articleCategory}', 'ArticleCategoryController@update');
You should be able to use $this->articleCategory
in your ArticleCategoryRequest
. And if there is implicit model binding you should be able to get the $this->articleCategory->id
.
Upvotes: 1