我試圖在註冊用戶後返回一個包含成功訊息的視圖,其中包含指向登入頁面的鏈接,但是會話訊息不會隨視圖一起傳遞。
這是我的 registred()
方法
protected function registered(Request $request, $user) { return view('frontend.pages.register-success')->with('message', 'Your registration was successful. Click the button below to login to your account'); }
這是查看頁面
@extends('frontend.layouts.main') @section('title', 'Registration successful') @section('content') <!-- Main Content --> <div id="main-content" class="site-main clearfix"> @if (Session::has('message')) <section class="popup"> <div class="popup-inner"> <div class="popup-content"> <div class="img"> <img src="assets/img/popup/popup.jpg" alt="Image"> </div> <div class="content text-center"> <p class="">{{ Session::get('message') }}</p> <h6 class="heading">REGISTRATION SUCCESSFUL!</h6> <a href="{{ route('login') }}" class="button color-2 login-submit">LOGIN TO YOUR ACCOUNT</a> </div> </div> </div> </section> @endif </div><!-- /#main-content --> @endsection
P粉0546168672023-11-13 14:14:40
我們可以使用 session() 全域助手來取代 Session:
// flash message create session()->flash('message', 'This is a message!'); session()->flash('alert-class', 'alert-danger');
從您的刀片檔案中透過按鍵取得閃存訊息
@if(session()->has('message'))@endif