我正在尝试使用Entrust在Laravel 5.5上应用角色和权限。
我使用它,作为:App \ models \ Role.php
中的文档<?php namespace App;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
$owner = new Role();
$owner->name = 'owner';
$owner->display_name = 'Project Owner'; // optional
$owner->description = 'User is the owner of a given project'; // optional
$owner->save();
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description = 'User is allowed to manage and edit other users'; // optional
$admin->save();
$manager = new Role();
$manager->name = 'manager';
$manager->display_name = 'Company Manager'; // optional
$manager->description = 'User is a manager of a Department'; // optional
$manager->save();
}
?>
但是,当我尝试将角色分配给我收到此问题的用户时:
{
..
$owner = new Role();
$owner->name = 'owner';
...
}
"Parse error: syntax error, unexpected '$owner' (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST)"
你能告诉我吗?
答案 0 :(得分:0)
功能/方法怎么样? ;)
<?php namespace App;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
public function setup()
{
$owner = new Role();
$owner->name = 'owner';
$owner->display_name = 'Project Owner'; // optional
$owner->description = 'User is the owner of a given project'; // optional
$owner->save();
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description = 'User is allowed to manage and edit other users'; // optional
$admin->save();
$manager = new Role();
$manager->name = 'manager';
$manager->display_name = 'Company Manager'; // optional
$manager->description = 'User is a manager of a Department'; // optional
$manager->save();
}
}