[laravel] Laravel Redirect Back with () 메시지

치명적인 오류가 발생하면 메시지와 함께 이전 페이지로 리디렉션하려고합니다.

App::fatal(function($exception)
{
    return Redirect::back()->with('msg', 'The Message');
}

뷰에서 msg에 액세스하려고합니다.

Sessions::get('msg')

그러나 아무것도 렌더링되지 않습니다. 여기서 뭔가 잘못하고 있습니까?



답변

시험

return Redirect::back()->withErrors(['msg', 'The Message']);

그리고 당신의 견해 안에서 이것을 부르십시오.

@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif


답변

라 라벨 5 이상

제어 장치

 return redirect()->back()->with('success', 'your message,here');   

잎:

@if (\Session::has('success'))
    <div class="alert alert-success">
        <ul>
            <li>{!! \Session::get('success') !!}</li>
        </ul>
    </div>
@endif


답변

다른 접근법은

제어 장치

use Session;

Session::flash('message', "Special message goes here");
return Redirect::back();

전망

@if (Session::has('message'))
   <div class="alert alert-info">{{ Session::get('message') }}</div>
@endif


답변

Laravel 5.4에서 다음이 나를 위해 일했습니다.

return back()->withErrors(['field_name' => ['Your custom message here.']]);


답변

오류가 있습니다 (맞춤법 오류).

Sessions::get('msg')// an extra 's' on end

해야한다:

Session::get('msg')

나는 지금 작동해야한다고 생각합니다.


답변

플래시 메시지를 설정하고 컨트롤러 기능에서 다시 리디렉션하십시오.

    session()->flash('msg', 'Successfully done the operation.');
    return redirect()->back();

그런 다음 뷰 블레이드 파일에서 메시지를 얻을 수 있습니다.

   {!! Session::has('msg') ? Session::get("msg") : '' !!}


답변

라 라벨 5.5에서 :

return back()->withErrors($arrayWithErrors);

블레이드를 사용한보기에서 :

@if($errors->has())
    <ul>
    @foreach ($errors->all() as $error)
        <li>{{ $error }}</li>
    @endforeach
    </ul>
@endif