Laravel Errors

Important Points

For any new project, Laravel logs errors and exceptions in the App\Exceptions\Handler class, by default. They are then submitted back to the user for analysis.

When your Laravel application is set in debug mode, detailed error messages with stack traces will be shown on every error that occurs within your web application.

By default, debug mode is set to false and you can change it to true. This enables the user to track all errors with stack traces. .env file

The value is set to true in a local development environment and is set to false in a production environment.
If the value is set to true in a production environment, the risk of sharing sensitive information with the end users is higher.

File name : index.php


Error Log

The log information can be configured in the web application in config/app.php file.

The logging parameters used for error tracking are single, daily, syslog and errorlog.

File name : index.php

'log' => env('APP_LOG',’daily’),
‘log_max_files’ => 25;
'log_level' => env('APP_LOG_LEVEL', 'error')

File name : index.php


A temporary file could not be opened to write the porcess output. fopen(C://windows/Temp/sf_proc_00.out.lock): failed to open stream . permission denied.

Runtime Exception

composer dump-autoload

PHP temp directory (C:\Users\hp\AppData\Local\Temp) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini

set path in php.ini file
sys_temp_dir = "C:\Users\hp\AppData\Local\Temp"

how to solve Laravel Specified key was too long error

when we run the following command we get “Specified key was too long error”

Easiest way to fix error is to locate the file “app/Providers/AppServiceProvider”, and add following line of code to the top of the file

use Illuminate\Support\Facades\Schema;

and inside the boot method set a default string length as given below

Schema::defaultStringLength(191);

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
Schema::defaultStringLength(191);

}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

Now delete tables created and run the following command again –
php artisan migrate

Fix No application encryption key has been specified error In Laravel

Sometime in laravel, when you created a fresh laravel project and trying to start development server you may encounter following error –

fix this error you need to set a key option in your config/app.php configuration file. You should use the following commands to generate this key and get the error fixed –

php artisan key:generate

php artisan config:cache

Laravel 5 Fix Ajax Post 500 Internal Server Error

when trying to submit form data using ajax you encounter 500 internal server error, in most of the cases this happens due to not adding csrf_token with form data or not setting X-CSRF-TOKEN request header with ajax form submit request.

Add CSRF Meta and Set Ajax Headers

Add CSRF Token In Meta tag :-
<meta name="csrf-token" content="{{ csrf_token() }}">


Set CSRF Token In jQuery Ajax Header :-

$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});

419 page expired error in laravel

the problem is caused by the csrf_token.

419 | page this error means laravel security issue it means csrf token field is not used correctly. use {{csrf_field}} and your issue will be solved. Actually CSRF is a session based token. Add your route in a route group and add a middleware which control the sessions.

Condition one:
If show error after submitting the form then you need to add the CSRF field in your form.
<form method="POST" action="/profile">
@csrf
...
</form>


Condition Two:
If show error after calling the AJAX then you need to add a header like below.
In your head tag
<meta name="csrf-token" content="{{ csrf_token() }}">

In Your Script tag
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});

Non-static method Illuminate\Http\Request::all() should not be called statically

The error message is due to the call not going through the Request facade.

Change

use Illuminate\Http\Request;
To

use Request;

419|page expired error when trying to login

If you getting a page expired ( 419 ) issue means an issue with your csrf token.

Condition 1 : If you are getting an error after submitting the form then you need to add the CSRF field in your form. the example provided on below post.

<form method="POST" action="/profile">
@csrf <!-- add csrf field on your form -->
...
</form>




Condition 2 : If you are getting an error after calling the AJAX then you need to add a header like below.

In your head tag

<meta name="csrf-token" content="{{ csrf_token() }}">

In Your Script tag

$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});


disable csrf protection

Note: disable csrf protection use only for webhooks

disable csrf protection field for routes group or specific routes

open file VerifyCsrfToken.php on your project

dir - App\Http\Middleware\VerifyCsrfToken.php

<?php namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
protected $except = [
'payment/*', // routes group
'specific-route', // specific route
];
}


check your .env file, for SESSION_DOMAIN, use empty if you are local (127.0.0.1...)

SESSION_DOMAIN=



or put your actual domain if you are live

SESSION_DOMAIN=domain.com

Undefined offset: 0 (View: C:\xampp\htdocs\schoolmanagement\resources\views\displaycombinedata.blade.php)

You should first check if the result is empty, and try to get the property only if it's not empty.

@if (!empty($result))
<td>{{($result[0]->students_id)}}</td>
<td>{{($result[0]->students_name)}}</td>
<td>{{($result[0]->students_class)}}</td>
<td>{{($result[0]->students_age)}}</td>
<td>{{($result[0]->class_teacher)}}</td>
@endIf


########################### OR #########################

@if(count($company_info) > 0)

<p> {{$company_info[0]->title}} </p>

@endIf

########################### OR #########################
@if(count($result1))


@endIf

Error - 419 Sorry your session has expired Post request in Laravel

add {{csrf_field}} to @csrf

case 1 : if you are running project in your local system like 127.0.01:8000 ,

then

add SESSION_DOMAIN= in your .env file

or in your config/session.php 'domain' => env('SESSION_DOMAIN', ''),

and then run php artisan cache:clear

case 2: if project is running on server and you have domain like "mydomain.com"

add SESSION_DOMAIN=mydomain.com in your .env file

or in your config/session.php 'domain' => env('SESSION_DOMAIN', 'mydomain.com'),

and then run php artisan cache:clear


419 | page expired

Alternatively, you can create a token input manually, using csrf_token() method. Outcome will be identical.

<!-- Equivalent for @csrf directive -->
<input type="hidden" name="_token" value="{{ csrf_token() }}">





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here


Ittutorial