Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel error Declaration of App\Exceptions\Handler::report(Throwable $exception) [closed]

Tags:

php

laravel

I'm using Laravel 6 and getting the following error when deploying to a shared host running PHP 7.3:

App\Exceptions\Handler::report(Throwable $exception)

Declaration of App\Exceptions\Handler::report(Throwable $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Exception $e) in /home/kb2hm3y8r4wm/public_html/laravel.supremeanimation.com/app/Exceptions/Handler.php on line 8

like image 734
Kamaljeet Singh Avatar asked Mar 13 '20 12:03

Kamaljeet Singh


People also ask

How do I get Exception error in Laravel?

In Laravel 5 you can catch exceptions by editing the render method in app/Exceptions/Handler. php . This will be applied to ANY exception in AJAX requests. If your app is sending out an exception of App\Exceptions\MyOwnException , you check for that instance instead.

What is Exception handler in Laravel?

By default, the Laravel exception handler will convert exceptions into an HTTP response for you. However, you are free to register a custom rendering closure for exceptions of a given type. You may accomplish this via the renderable method of your exception handler.

What is throwable Laravel?

Throwable is the base interface for any object that can be thrown via a throw statement, including Error and Exception.

How to report exceptions in Laravel?

Behind the scenes, Laravel already ignores some types of errors for you, such as exceptions resulting from 404 HTTP "not found" errors or 419 HTTP responses generated by invalid CSRF tokens Try updating your report method to this, this should send an email for every exception, regardless of the type. Link to the docs for reporting exceptions.

How do I fix error 755 in Laravel?

This is a common error message that we get when setting up laravel project for the first time. We can easily fix this error by changing the owner of app/storage folder to ‘www-data’ and ensuring the permission is set to 755. Now, let’s discuss how our Support Engineers fix this error. How we fix laravel error in exception handler?

How to clear the compiled class file in Laravel?

Normally you can use php artisan clear-compiled to remove the compiled class file, but you're trapped in a catch 22 because in order to run the command, Laravel will use... the compiled cache file throwing the error you got. So try removing the file manually, and you should be good to go.

How to make Laravel more performant?

To make things more performant, Laravel caches quite some stuff in /bootstrap/cache. I ran into the same issue before, and removing the /bootstrap/cache/compiled.php might actually resolve this.


1 Answers

I think the error you're getting is due to changes on Laravel 7 (not 6), as you can see on Laravel 7 upgrade guide. Check this:

  • For Laravel < 7:

    The report and render methods of your application's App\Exceptions\Handler class should accept instances of the Exception interface instead of Throwable instances:

    use Exception;
    
    public function report(Exception $exception);
    public function render($request, Exception $exception);
    
  • For Laravel >= 7:

    The report and render methods of your application's App\Exceptions\Handler class should accept instances of the Throwable interface instead of Exception instances:

    use Throwable;
    
    public function report(Throwable $exception);
    public function render($request, Throwable $exception);
    
like image 86
Hafez Divandari Avatar answered Sep 20 '22 13:09

Hafez Divandari