英文:
Add successful message in blade with Laravel 10
问题
我在控制器中添加了一个成功消息,但在将数据插入数据库后,成功消息未显示。希望专家能帮助。
这是我的HTML代码:
<form action="{{url('/')}}/register" method="post">
@csrf
<div class="fields">
<div class="input-field">
<label for="fn" id="Fn">名字</label>
<div class="inpt">
<input type="text" id="fn" name="First_Name" placeholder="输入您的名字" />
</div>
</div>
</div>
<div class="input-field">
<label for="ln" id="Ln">姓氏</label>
<div class="inpt">
<input type="text" id="ln" name="Last_Name" placeholder="输入您的姓氏" />
</div>
</div>
<div class="input-field">
<label for="email">电子邮件</label>
<div class="inpt">
<input type="text" id="email" name="email" placeholder="输入您的电子邮件" required />
</div>
</div>
</form>
这是我的控制器:
Registrationform::create($request->all());
return redirect()->route('register')->withSuccess('您已成功注册!');
这是我的路由:
Route::get('/register', [Registrationcontroller::class,'register'])->name('register');
Route::post('/register', [Registrationcontroller::class,'store']);
英文:
I add a with-success message in the controller but after inserting data in the database, the successful message not showing. Hoping an expert help.
This is my HTML code:
<form action="{{url('/')}}/register" method="post">
@csrf
<div class="fields">
<div class="input-field">
<label for="fn" id="Fn">First Name</label>
<div class="inpt">
<input type="text" id="fn" name="First_Name" placeholder="Enter Your First Name" />
</div>
</div>
</div>
<div class="input-field">
<label for="ln" id="Ln">Last Name</label>
<div class="inpt">
<input type="text" id="ln" name="Last_Name" placeholder="Enter Your Last Name" />
</div>
</div>
<div class="input-field">
<label for="email">E-mail</label>
<div class="inpt">
<input type="text" id="email" name="email" placeholder="Enter Your Email" required />
</div>
</div>
</form>
This is my controller:
Registrationform::create($request->all());
return redirect()->route('register')->withSuccess('You have registered successfully!');
This is my route:
Route::get('/register', [Registrationcontroller::class,'register'])->name('register');
Route::post('/register', [Registrationcontroller::class,'store']);
答案1
得分: 3
You're doing Laravel's flash messaging correctly, but you missed the display part. In the end of the form add this:
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
Edit 01
For Laravel 10:
@if ($message = Session::get('success'))
@endif
英文:
You're doing Laravel's flash messaging correctly, but you missed the display part. In end of the form add this
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
Edit 01
For laravel 10
@if ($message = Session::get('success'))
@endif
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论