Laravel Spatie 权限 - 如何通过另一个模型更改默认模型 'role'
Laravel Spatie Permissions - how to change default model 'role' by another model
请问我如何更改默认模型 'role' 我项目中的另一个模型(laravel 项目)具有与 'role' 相同的体系结构;默认模型包。
在 config/permission.php 配置文件中包含:
'models' => [
/*
* When using the "HasPermissions" trait from this package, we need to know which
* Eloquent model should be used to retrieve your permissions. Of course, it
* is often just the "Permission" model but you may use whatever you like.
*
* The model you want to use as a Permission model needs to implement the
* `Spatie\Permission\Contracts\Permission` contract.
*/
'permission' => Spatie\Permission\Models\Permission::class,
/*
* When using the "HasRoles" trait from this package, we need to know which
* Eloquent model should be used to retrieve your roles. Of course, it
* is often just the "Role" model but you may use whatever you like.
*
* The model you want to use as a Role model needs to implement the
* `Spatie\Permission\Contracts\Role` contract.
*/
'role' => Spatie\Permission\Models\Role::class,
],
我想要这样的东西:
'role' => App\Fonction::class,
文档说我必须实现
Spatie\Permission\Contracts\Role` 合同。
知道我怎样才能以正确的方式做到这一点。
函数模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Fonction extends Model
{
protected $fillable = [
'nom','description'
];
public function comptes()
{
return $this->hasMany('App\Compte') ;
}
}
您可以扩展 Spatie\Permission\Models\Role
class。它已经实现了 Spatie\Permission\Contracts\Role
接口。在 doc.
中查看详细信息
<?php
namespace App;
use Spatie\Permission\Models\Role;
class Fonction extends Role
{
protected $fillable = [
'nom','description'
];
public function comptes()
{
return $this->hasMany('App\Compte') ;
}
}
请问我如何更改默认模型 'role' 我项目中的另一个模型(laravel 项目)具有与 'role' 相同的体系结构;默认模型包。
在 config/permission.php 配置文件中包含:
'models' => [
/*
* When using the "HasPermissions" trait from this package, we need to know which
* Eloquent model should be used to retrieve your permissions. Of course, it
* is often just the "Permission" model but you may use whatever you like.
*
* The model you want to use as a Permission model needs to implement the
* `Spatie\Permission\Contracts\Permission` contract.
*/
'permission' => Spatie\Permission\Models\Permission::class,
/*
* When using the "HasRoles" trait from this package, we need to know which
* Eloquent model should be used to retrieve your roles. Of course, it
* is often just the "Role" model but you may use whatever you like.
*
* The model you want to use as a Role model needs to implement the
* `Spatie\Permission\Contracts\Role` contract.
*/
'role' => Spatie\Permission\Models\Role::class,
],
我想要这样的东西:
'role' => App\Fonction::class,
文档说我必须实现 Spatie\Permission\Contracts\Role` 合同。 知道我怎样才能以正确的方式做到这一点。
函数模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Fonction extends Model
{
protected $fillable = [
'nom','description'
];
public function comptes()
{
return $this->hasMany('App\Compte') ;
}
}
您可以扩展 Spatie\Permission\Models\Role
class。它已经实现了 Spatie\Permission\Contracts\Role
接口。在 doc.
<?php
namespace App;
use Spatie\Permission\Models\Role;
class Fonction extends Role
{
protected $fillable = [
'nom','description'
];
public function comptes()
{
return $this->hasMany('App\Compte') ;
}
}