I have this trait
HasExtendedRoles.php
trait HasExtendedRoles
{
use HasRoles;
use HasExtendedPermissions {
HasExtendedPermissions::getPermissionClass insteadof HasRoles;
HasExtendedPermissions::scopePermission insteadof HasRoles;
HasExtendedPermissions::permissions insteadof HasRoles;
}
protected ?Form $currentForm = null;
public function forForm(string|int|Form $form): self
{
if (!$form instanceof Form) {
$form = Form::when(
is_numeric($form),
fn(Builder $q) => $q->where('id', $form),
fn(Builder $q) => $q->where('slug', $form)
)->firstOrFail();
}
$this->currentForm = $form;
return $this;
}
}
I also have this trait
HasExtendedPermissions.php
trait HasExtendedPermissions
{
use HasPermissions;
protected ?Form $currentForm = null;
public function forForm(string|int|Form $form): self
{
if (!$form instanceof Forsm) {
$form = Form::when(
is_numeric($form),
fn(Builder $q) => $q->where('id', $form),
fn(Builder $q) => $q->where('slug', $form)
)->firstOrFail();
}
$this->currentForm = $form;
return $this;
}
}
And in my User model
class User extends Authenticatable
{
use HasExtendedRoles;
}
And in my controller, I do
dd($user->forForm($form)->permissions);
Now the HasExtendedPermissions
trait doesn't seam to inherit $this->currentForm
.
But when I do:
dd($user->forForm($form)->roles);
Which is available through the HasExtendedRoles trait, it works perfectly, I was thinking about creating another forForm
method inside the HasExtendedPermissions
trait with a diffrent name but I hope to minimize code duplication as much as possible.
What could I possibly be doing wrongly?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744870170a4598212.html
评论列表(0条)