পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Thursday, March 2, 2017

Laravel - Error Handling

In Laravel all the exceptions are handled by app\Exceptions\Handler class. This class contains two methods — report and render.

report() method

report() method is used to report or log exception. It is also used to send log exceptions to external services like Sentry, Bugsnag etc.

render() method

render() method is used to render an exception into an HTTP response which will be sent back to browser.
Beside these two methods, the app\Exceptions\Handler class contains an important property called “$dontReport”. This property takes an array of exception types that will not be logged.

HTTP Exceptions

Some exceptions describe HTTP error codes like 404, 500 etc. To generate such response anywhere in an application, you can use abort() method as follows.
abort(404)

Custom Error pages

Laravel makes it very easy for us to use the custom error pages for each separate error codes. For example, if you want to design custom page for error code 404, you can create a view at resources/views/errors/404.blade.php. Same way, if you want to design error page for error code 500, it should be stored at resources/views/errors/500.blade.php.

Example

Step 1 − Add the following lines in app/Http/routes.php.
app/Http/routes.php
Route::get('/error',function(){
   abort(404);
});
Step 2 − Create a view file called resources/views/errors/404.blade.php and copy the following code in that file.
resources/views/errors/404.blade.php
<!DOCTYPE html>
<html>
    
   <head>
      <title>404</title>
      <link href = "https://fonts.googleapis.com/css?family=Lato:100" rel = "stylesheet" 
         type = "text/css">
   
      <style>
         html, body {
            height: 100%;
         }
         body {
            margin: 0;
            padding: 0;
            width: 100%;
            color: #B0BEC5;
            display: table;
            font-weight: 100;
            font-family: 'Lato';
         }
         .container {
            text-align: center;
            display: table-cell;
            vertical-align: middle;
         }
         .content {
            text-align: center;
            display: inline-block;
         }
         .title {
            font-size: 72px;
            margin-bottom: 40px;
         }
      </style>
  
   </head>
   <body>
 
      <div class = "container">
         <div class = "content">
            <div class = "title">404 Error</div>
         </div>
      </div>
  
   </body>
</html>
Step 3 − Visit the following URL to test the event.
http://localhost:8000/error
Step 4 − After visiting the URL, you will receive the following output −
404Error

No comments:

Post a Comment