我从这里成功安装了 voyager admin
在我的客户页面上,我创建了一个源自 auth 的自定义注册。我可以成功注册用户。
安装 voyager admin 后,我在客户的注册表单上添加了一个新用户。然后,当我尝试访问http://localhost:8000/admin
然后出现错误,如图所示。
下面是第 53 行的图像:
以下是 VoyagerUse.php 的完整代码
<?php
namespace TCG\Voyager\Traits;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use TCG\Voyager\Facades\Voyager;
use TCG\Voyager\Models\Role;
/**
* @property \Illuminate\Database\Eloquent\Collection roles
*/
trait VoyagerUser
{
public function role()
{
return $this->belongsTo(Voyager::modelClass('Role'));
}
/**
* Check if User has a Role(s) associated.
*
* @param string|array $name The role to check.
*
* @return bool
*/
public function hasRole($name)
{
if (!$this->relationLoaded('role')) {
$this->load('role');
}
return in_array($this->role->name, (is_array($name) ? $name : [$name]));
}
public function setRole($name)
{
$role = Voyager::model('Role')->where('name', '=', $name)->first();
if ($role) {
$this->role()->associate($role);
$this->save();
}
return $this;
}
public function hasPermission($name)
{
if (!$this->relationLoaded('role')) {
$this->load('role');
}
if (!$this->role->relationLoaded('permissions')) {
$this->role->load('permissions');
}
return in_array($name, $this->role->permissions->pluck('key')->toArray());
}
public function hasPermissionOrFail($name)
{
if (!$this->hasPermission($name)) {
throw new UnauthorizedHttpException(null);
}
return true;
}
public function hasPermissionOrAbort($name, $statusCode = 403)
{
if (!$this->hasPermission($name)) {
return abort($statusCode);
}
return true;
}
}