返回withSuccess withErrors丢失

时间:2016-06-01 13:24:45

标签: laravel laravel-5 laravel-5.2

我使用请求验证来验证我的表单帖子,该表单适用于"简单"联系课程,但不是我的职位课程。

工作:

ContractController GET:

public function showForm()
    {
        return view('contact');
    }

ContractController POST:

public function sendContactInfo(ContactRequest $request)
    {
blabla
return back()
            ->withSuccess("Thank you");
}

无效:

postcontroller GET:

public function changepost($postid)
    {

        $postdetail = posts::find($postid);
blabla
return view('changepost')->with("postdetail", $postdetail);
}

postcontroller POST:

public function changepostvalues(changepostreqeust $request)
    {
blabla
return back()->withSuccess("Thank you");
}

withSuccesswithError仅存储在下一个请求中,对吗? 我也尝试使用Session:flash得到相同的结果,成功和错误不在会话中。 当我尝试Session::put时,一切正常。但是,我不想永久地将这个消息存储在会话中,我也想了解为什么这些信息会丢失......

我认为它与return view('changepost')->with("postdetail", $postdetail);有关,我需要传递错误和成功消息......

感谢。

修改 添加视图

@extends('master')

@section('title', 'lala')

@section('sidebar')
    @parent

@endsection

@section('page-script')

        <link href="{{ asset('/packages/dropzone/dropzoneaddpost.css') }}" rel="stylesheet">


        @foreach($images as $image)
            <meta name="postimage" content="{{$image->image_path}}" id="{{$image->id}}">
        @endforeach


@stop
@section('content')
    <div align="center">
        <div class="addpost">
            @if (Session::has('success'))
                <div class="alert alert-info">{{ Session::get('success') }}</div>
            @endif


            <div class="row">
                <div class="files" id="previews">
                <div id="template" class="file-row">
                    <!-- This is used as the file preview template -->
                    <div>
                        <span class="preview"><img data-dz-thumbnail /></span>
                    </div>
                    <div>
                        <strong class="error text-danger" data-dz-errormessage></strong>
                    </div>
                    <div style="text-align: center;">

                        <button data-dz-remove class="btn delete mydelbutton">
                            <i class="glyphicon glyphicon-trash"></i>
                        </button>
                    </div>
                </div>
                </div>
            </div>
            <div class="row">

                <form action="/changepost" method="post">
                <div class="form-group">
                    <label for="txttitle">Titel:</label>
                    <input class="form-control" id="txttitle" type="text" name="beschreibung" id="beschreibung" maxlength="45" style="" value='{{ $postdetail->beschreibung }}'>
                    <label for="txtmessage">Beschreibung:</label>
                    <textarea id="txtmessage" class="form-control" rows="5" name="description" id="description" maxlength="500">{{$postdetail->text}}</textarea>
                </div>
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <input type="hidden" name="postid" value="{{ $postdetail->id }}">


                <button id="savepost" class="btn mybutton start">
                    <i class="glyphicon glyphicon-upload"></i>
                    <span>Save</span>
                </button>
               </form>
            </div>
            </div>
        </div>
    </div>
    <script src="{{ asset('/packages/dropzone/dropzone.js') }}"></script>
    <script src="{{ asset('/packages/dropzone/dropzone-config.js') }}"></script>
@stop

1 个答案:

答案 0 :(得分:0)

尝试这样做

 return redirect('the route you want')->with('success','thank you');

你可以分享观看代码吗?