【发布时间】:2020-06-29 10:00:42
【问题描述】:
我正在使用 laravel 5.8 创建用户角色和权限,并且当我想运行 PermissionTableSeeder 并在 cmd 中运行时,如下所示:
php artisan db:seed --class=PermissionTableSeeder .
但它显示此错误:
php 致命错误:无法重新声明 App\Exceptions\Handler::render() in G:\Xampp\htdocs\blog\app\Exceptions\Handler.php 在第 55 行,这是 我的代码:
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler {
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
public function render($request, Exception $exception) {
if ($exception instanceof \Spatie\Permission\Exceptions\UnauthorizedException) {
return response()->json(['User have not permission for this page access.']);
}
return parent::render($request, $exception);
}
}
【问题讨论】:
-
您在同一个类中声明了两个名为
render()的函数。同一范围内不能有两个同名的函数。
标签: php laravel cmd laravel-5.8