Answer the question
In order to leave comments, you need to log in
Yii2 - how to create a rule for editing?
How to correctly create a rule so that the post can be edited by a user with the admin role and the author of the post (post.user_id == user.id), if editing is allowed (allowEdit == true)? And how to use it then?
Answer the question
In order to leave comments, you need to log in
There are two options.
1. In code:
if (Yii::$app->user->can('admin') || $post->user_id == Yii::$app->user->id) {
// ...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question