简体   繁体   中英

i want to redirect user with a message from formRequest

i want to send a response with forbiddenResponse() method which doesn't seem to work in laravel 5.8

CategoryDestroyRequest

  class CategoryDestroyRequest extends FormRequest
  {
       
      public function authorize()
      {
          return !($this->route('category') == config('cms.default_category_id'));

      }

       public function forbiddenResponse(){
          return redirect()->back()->with('message','you can't delete default category);
       }
  }

      
       

thans in advance.

You could try to override the failedAuthorization method since that is what gets called on failed authorization. You can throw an HttpResponseException and set your own response on it:

use Illuminate\Http\Exceptions\HttpResponseException;

protected function failedAuthorization()
{
    throw new HttpResponseException($this->forbiddenResponse());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM