1
votes

I am creating a User Roles and Permissions using laravel 5.8, and in that when I want to run PermissionTableSeeder and i run in cmd like this:

php artisan db:seed --class=PermissionTableSeeder .

But it showing this error:

php fatal error: cannot redeclare App\Exceptions\Handler::render() in G:\Xampp\htdocs\blog\app\Exceptions\Handler.php on line 55 and this is my code:

<?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);
}

}
1
you have declared two functions called render() inside the same class. You can't have two functions with the same name in the same scope.ADyson

1 Answers

0
votes

You cannot declare/create two function with same name as below:

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.']);
}

To solve this remove first function and add parent::render($request, $exception); in other as below

 public function render($request, Exception $exception) {   
    return parent::render($request, $exception); // add here
       if ($exception instanceof \Spatie\Permission\Exceptions\UnauthorizedException) {
        return response()->json(['User have not permission for this page access.']);
    }