Laravel bład make:seeder

0

witam robię system uprawnień z kursu https://www.itsolutionstuff.com/post/laravel-6-user-roles-and-permissions-from-scratch-laravel-6-aclexample.html

Step 11

Wywala mi ciągle bład przy seedowaniu. Po komędzie

php artisan make:seeder PermissionTableSeeder

wyskakuje mi poniższy błąd. Co może być problemem? plik Handler.php mam skompilowany tak jak w kursie.
Treść błedu:

$ php artisan make:seeder PermissionTableSeeder                                                                                                                                                     
 PHP Fatal error:  Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e) in C:\xampp\htdocs\Roles\blog\app\Exceptions\Handler.php on line 8
PHP Fatal error:  Uncaught ReflectionException: Class App\Exceptions\Handler does not exist in C:\xampp\htdocs\Roles\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php:803
Stack trace:
#0 C:\xampp\htdocs\Roles\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php(803): ReflectionClass->__construct('App\\Exceptions\\...')
#1 C:\xampp\htdocs\Roles\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php(681): Illuminate\Container\Container->build('App\\Exceptions\\...')
#2 C:\xampp\htdocs\Roles\blog\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(787): Illuminate\Container\Container->resolve('App\\Exceptions\\...', Array, false)
#3 C:\xampp\htdocs\Roles\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php(265): Illuminate\Foundation\Application->resolve('App\\Exceptions\\...', Array, false)
#4 C:\xampp\htdocs\Roles\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php(799): Illuminate\Container\Container->Illuminate\Container\{closure} in C:\xampp\htdocs\Roles\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 805

Natomiast mój plik Handler.php poniżej. Co może być przyczyną tego błedu?

<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

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  \Exception  $exception
     * @return void
     *
     * @throws \Exception
     */
    public function report(Exception $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @throws \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

No przecież jak byk jest napisane, że masz metodę niekompatybilną pod względem typu parametru...

1

Komunikat o błędzie:
Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e)
Twoja metoda:

public function report(Exception $exception)
   {
       parent::report($exception);
   }

Zwróć uwagę na różnice w przyjmowanych parametrach.

1

Bo zapewne używasz innej wersji larvy niż masz w kursie przez co kopiujesz niekompatybilny kod.

1

Może używasz innej wersji Laravel niż w kursie, nie wiem. Nie mniej klasa Throwable to nie to samo co klasa Exception.
Wpisz poprawnie typy argumentów i zobacz czy działa.

1

Najnowsza wersja larvy ma throwable https://github.com/laravel/laravel/blob/master/app/Exceptions/Handler.php więc masz plik handler (pewnie nie tylko) od wersji 5.x a biblioteki/bibliotekę od 6.x

0

mr_jaro masz racje !!! zamieniłem te nazwy na throwable i działa !!! Dzięki

1 użytkowników online, w tym zalogowanych: 0, gości: 1