如何在Laravel中從資料庫中呼叫特定資料並添加到我的消息中
P粉111227898
P粉111227898 2023-08-06 20:00:44
0
1
506
<p>如何將特定資料的名稱包含在我的回傳訊息訊息中?<br /><br />>使用者控制器:</p><p><strong>< /strong> ;</p>
公用函數process(Request $request){
    $validated = $request->validate([
       “電子郵件”=> ['必填', '電子郵件'],
       '密碼' => '必需的'
    ]);

    if(auth()->嘗試($validated)){
       $request->session()->regenerate();

       return redirect('/')->with('information-message', '歡迎回來!');
    }

    return redirect('login')->with('failed-message', '登入失敗,請重試!');

 }</pre>
<p><strong>information-message.blade.php:</strong></p>
@if (session()->has('訊息訊息'))

<div x-data="{show : true}" x-show="show" x-init="setTimeout(() => show = false, 5000)" class="flex 固定 m-2 底部- 0 right-0 z-20 items-center bg-blue-700 text-white text-sm font-bold px-4 py-3" role="alert">
    <路徑 d =「M12 .432 0c1.34 0 2.01.912 2.01 1.957 0 1.305-1.164 2.512-2.679 2.512-1.269 0-2.009-.75-1.974-1.9491. 0zM8.309 20c-1.058 0-1.833 -. 652-1.093-3.524l1.214-5.092c.211-.814.246-1.141 0-1.141-.317 0-1.689.562-2.502 1.117l-.528-688.38-5.76. 01- 3.467 1.057 0 1.233 1.273.705 3.23l-1.391 5.352c-.246.945-.141 1.271.106 1.271.317 0 1.357-.392 106 1.271.317 0 1.357-.392 106 1.271.317 0 1.357-.392 106.3891. 9.365 20 8.309 20z">>< /svg >
    <p>{{session('訊息訊息')}}

@endif</pre>
<p>如果登入成功:我希望輸出變成回報!(登入的使用者的姓名)。</p>            
P粉111227898
P粉111227898

全部回覆(1)
P粉403804844

您可以使用 Auth 門面來取得目前使用者。

Auth::user()

根據你的情況

return redirect('/')->with('information-message', 'Welcome Back! '.Auth::user()->name);
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!