Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FaiChan's avatar

Return Back()->with('error','message') function , No Message and Session Lost

Hello everyone,

my form will submit a post to AbcController@updateTicket to process, it will go thought all $ticket->status.

my problem is $ticket->status "new" and "process" is working fine. but the last if else condition to using return back() function, it will be got the "No Message" error. I also found the session is empty.

I had no idea why the session will be empty when using return back()->with();

Please help me. Thanks so much! PS: my Laravel Version 5.6

Error Message

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
    protected function methodNotAllowed(array $others)
    {
        throw new MethodNotAllowedHttpException($others);
    }
 
    /**
     * Get routes from the collection by method.
     *
     * @param  string|null  $method
     * @return array
     */
    public function get($method = null)
    {
        return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);
    }
 Arguments

    1.""

Route

Route::post('/abc/updateTicket','AbcController@updateTicket')->name('abc.updateTicket');

View

 @if ( Session::has('errors'))
  <div class="alert alert-danger" align="center">
  <p>{{ $errors }}</p>
  </div>
@endif

<form class="form-inline" role="form" data-toggle="validator" name="search"
      action="{{ route('abc.updateTicket') }}" method="post">
      {!! csrf_field() !!}
 @if (!empty($txtTicketNo))
        <input type="text" class="form-control input-sm" id="txtTicketNo" name="txtTicketNo"
         value="{{ $txtTicketNo }}">
 @else
        <input type="text" class="form-control input-sm" id="txtTicketNo" name="txtTicketNo">
  @endif
         <button class="btn btn-default btn-sm" type="submit" name="btnTicketNo">Enter</button>
</form>

Controller

if ($ticket-status === "new" ){
     //  do something

    return view('abc.index', compact('ticket', 'txtTicketNo'));

 } elseif ($ticket-status === "process" ){
    // do somting

     return view('abc.index', compact('ticket', 'txtTicketNo'));

}else{

       return back()-with('error',' error message');
}
0 likes
2 replies
flightsimmer668's avatar

@faichan Are you missing a > or is this just a typo? It's supposed to read:

else {

       return back()->with('error',' error message');
}

Parts of your controller code seem to be missing the >, like $ticket-status should be

$ticket->status
Snapey's avatar
Snapey
Best Answer
Level 122

Also, you will have strange issues if you return a view from a POST route. Never do this. Always return a redirect to a new route that shows the view.

Please or to participate in this conversation.