Professional Documents
Culture Documents
developers
Source:
https://decodeweb.in/php/php-frameworks/laravel-framework/5-common-errors-in-laravel-which-haunt-new-develop
ers/
Hello readers ! hope you are doing fine and enjoying my blog. Laravel is beautiful, no doubt, but its error reporting
while in development environment is too much haunted. As far as I know everyone has seen a black and white
screen with millions of characters arranged line by line, even if there is a semicolon (;) missing.
Our today’s topic would be the top 5 common errors / exceptions or simply the mistakes new developers make
while working on Laravel which are:
1. MethodNotAllowedHttpException
2. 419 Error / Page Expired
3. File Permission for storage
4. ReflectionException / Class does not exist]
5. 500 Error
1. MethodNotAllowedHttpException
This is the most frequent occurring exception, as it says “Method is not allowed” but where ? Simply go to web.php
or api.php where you have written the routes and check if any route / url is using some other type of http method
instead of the intended method.
For example, if your route is using POST as method but you are calling as GET. As Laravel is too much concerned
about security, it will not allow POST route to be called as GET route hence this exception occurs.
Again, this exception is based on in-built application security. Error 419 or Page Expired comes when we do not
include CSRF_TOKEN in the html form body, since forms are usually the way to POST data to another file or
controller.
namespace App\Http\Middleware;
Same way for bootstrap directory we often get error like this. Hence best practice in would be to give both of these
directories access to write.
5. 500 Error
500 error is one of the scariest even for experienced developer, no offense, to debug this error first we need to
check if server is all good, second check will be how is a logic applied to source code. Many a times, as new
developers, we tend to make silly mistakes like, we redirect to the same page, to be specific a controller function,
hence on server end its stack gets full thus it is not available to handle more request.
If anything goes wrong on server, error code will be the same 500 even if root cause be whatever, try to write
sensitive codes in try-catch blocks at least we can be prevented by getting 500 errors.