Laravel重定向时没有消息错误

时间:2018-06-09 10:26:02

标签: php laravel

重定向到页面时,我收到NoMessages错误。

add.blade.php
@extends('layout.app')
@section('content')
{!! Form::open(['action' => 'AddluggageController@addconfirm','method'=>'POST']) !!}
<div class="form-group row">
    <div class="col-4">
        <h5 class="col-12"><b> Passenger Info</b> </h5> 
        <div class="col-12">
            {{form::label('name'), 'Name'}} 
            {{form::text('name','',['class'=>'form-control '])}} <br><br>
        </div>
        <div class="col-12">
            {{form::label('phone'), 'Phone'}} 
            {{form::text('phone','',['class'=>'form-control '])}}
        </div>
    </div>
sni</div>
    {!! Form::close() !!}
@endsection

AddluggageController.php

    public function addconfirm(){
     return redirect('/addsuccess')->with('success', 'Saved Successfully');
    }

web.php

Route :: post('/ addconfirm','AddluggageController @ addconfirm');

当我重定向时,它给了我

MethodNotAllowedHttpException

没有消息

2 个答案:

答案 0 :(得分:0)

将您的路线方法更改为GET
Route::get('/addconfirm', 'AddluggageController@addconfirm');

然后在您的刀片上添加以下内容:

@if (\Session::has('success'))

          {!! \Session::get('success') !!}
        
@endif

答案 1 :(得分:0)

根据您的评论,您需要将路线名称从addluggage

更改为addsuccess
 return redirect('/addluggage')->with('success', 'Saved Successfully');

每当您重定向时,get都不会post,因此请在您重定向的控制器中进行更改

public function addconfirm(){
   return view('addconfirm')->with('success', 'Saved Successfully');
   // here "addconfirm" is blade name as "addconfirm.blade.php" inside "resoruces/views" folder
}

您也可以从action更改为url

{!! Form::open(['url' => '/addconfirm','method'=>'POST']) !!}