Skip to main content

Show Error Page in Laravel in two ways

copy errors directory from resource views
-inside error directory create page 403.blade,202.blade ... same as the name inside the switch case of render function of handler.

 and

copy errormaster from layouts of resource

copy and paste code inside handler of exception folder in render function
paste the following code:
public function render($request, Exception $exception)
{
if ($this->isHttpException($exception)) {
$message = $exception->getMessage();
// dd($message);
switch ($exception->getStatusCode()) {

// not authorized
case '403':
return \Response::view('errors.403',array(compact('message')),403);
break;
case '202':
return \Response::view('errors.202',array(compact('message')),202);
break;

// not found
case '404':
return \Response::view('errors.404',array(compact('message')),404);
break;

// internal error
case '500':
return \Response::view('backend.errors.500',array(compact('message')),500);
break;

default:
return $this->renderHttpException($exception);
break;
}
} else {
return parent::render($request, $exception);
}
return parent::render($request, $exception);
}

always change  APP_debug of env file from true to false#important

default maa j xa tyo lai change app_debug thats all

 NEXT WAY:-
Simply go inside: vendor/laravel/src/illuminate/foundation/exceptions/views/404.blade.php
@extends('errors::illustrated-layout')

@section('code', '404')
@section('title', __('Page Not Found'))

@section('image')
<div style="background-image: url('/svg/404.svg');" class="absolute pin bg-cover bg-no-repeat md:bg-left lg:bg-center">
</div>
@endsection

@section('message', __('Sorry, the page you are looking for could not be found.'))

Sorry :) laravel 5.7 have provided this autometically ... but from here you can change message... by changing on the @section('message'_('custom message here'))

now its done hai ta

Best way of error handling in laravel 6 :
php artisan vendor:publish --tag=laravel-errors
then you will need to do following things:

in illustrated-layout.blade of error folder :
  <a href="{{ app('router')->has('home') ? route('home') : url('/') }}">
<button class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg">
{{ __('Go Home') }}
</button>
</a>


to
<a href="{{ app('router')->has('front.index') ? route('front.index') : url('/') }}">
<button class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg">
{{ __('Go Home') }}
</button>
</a>

now on each error page :
change the following:
@extends('errors::minimal')
to
@extends('errors::illustrated-layout')

Comments

Popular posts from this blog

Integration of adminlte admin pannel in laravel 6 adn above

Create new laravel project : laravel new projectname --auth Steps to integrate admin pannel i.e. adminlte 1.  composer require jeroennoten/laravel-adminlte 2.  php artisan adminlte:install 3.  php artisan adminlte:install --only=auth_views 4. php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\AdminLteServiceProvider" --tag=views Filemanager: https://unisharp.github.io/laravel-filemanager/installation 1.  composer require unisharp/laravel-filemanager:~1.8 php artisan vendor:publish --tag = lfm_config php artisan vendor:publish --tag = lfm_public 3.  php artisan route:clear php artisan config:clear you will get a problem regarding file relode after upload and to solve do this fix it on vendor\unisharp\laravel-filemanager\src\Controllers\UploadController.php replace line 60 return count($this->errors) > 0 ? $this->errors : parent::$success_response; by return count($this->errors) > 0 ? ...

laravel file manager sorting by time default

Ref :  https://github.com/UniSharp/laravel-filemanager/issues/337 To load files order by "time DESC" you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; } return strcmp($a->{$key_to_sort}, $b->{$key_to_sort}); }); return $arr_items; } with public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; ...

Convert Html PAge to PDF using Canvas

Link :https://www.quora.com/How-we-export-html-page-as-pdf-using-pure-javascript app.js ( function (){ var form = $ ( '. printme ' ), cache_width = form . width (), a4 =[ 595.28 , 841.89 ]; // for a4 size paper width and height $ ( '#create_pdf' ). on ( 'click' , function (){ $ ( 'body' ). scrollTop ( 0 ); createPDF (); }); //create pdf function createPDF (){ getCanvas (). then ( function (canvas){ var img = canvas. toDataURL ( "image/png" ), doc = new jsPDF ({ unit : 'px' , format : 'a4' }); doc . addImage ( img , 'JPEG' , 20 , 20 ); doc . save ( 'FinalPrint.pdf' ); form . width ( cache_width ); }); } // create canvas object function getCanvas (){ form . width (( a4 [ 0 ]* 1.33333 ) ...