Friday, April 27, 2018

How to redirect users to another page with session messages while error occuring - development

How to redirect users to another page with session messages while error occuring

I want to redirect users to admin page when any error occuring about the thujohn/twitter package. It throws Runtimeexception..

So I add couple code handler.php

public function render($request, Exception $exception)
{

    if ($exception instanceof RuntimeException) {
        return redirect()->route('admin.panel')
            ->with('message', 'Please try again later..')
            ->with('message_type','warning');

    } else {
        return parent::render($request, $exception);
    }
}

But when I say that, it redirects user at all exceptions even at 404 errors or Trying to get property of non-object erros.. How can I fix this ? I want to redirect user for just relevant error

Or is there any way to do redirect user with condition like below.

if($exception->code == 436){
  // it says member has protected access. I can't use it code property outside of the exception class
      return redirect()->route('admin.panel')
            ->with('message', 'Specific error message')
            ->with('message_type','warning');

 }



from Laravel Questions and Answers https://laravelquestions.com/laravel/how-to-redirect-users-to-another-page-with-session-messages-while-error-occuring/
via Lzo Media

No comments:

Post a Comment