我刚刚在表单提交上添加了一个祝酒词,但它不起作用,我不明白问题所在。
public function create(Request $data)
{
$data->validate([
'name' => 'required|string|max:255',
'phone' => 'required|unique:users|numeric|digits:11',
'cnic' => 'nullable|unique:users|numeric|digits:13',
'email' => 'required|string|email|max:255|unique:users',
'designation' => 'nullable|string',
'department' => 'nullable|string',
'password' => 'required|string|min:4',
]);
User::create([
'name' => $data['name'],
'phone' => $data['phone'],
'cnic' => $data['cnic'],
'email' => $data['email'],
'role' => $data['role'],
'designation' => $data['designation'],
'department' => $data['department'],
'password' => Hash::make($data['password']),
]);
return redirect()->route('manage-users')->with('message', 'User created successfully!');
}这是我的控制器,我在刀片式服务器中以这种方式使用
@if(Session::has('message'))
toastr.info("{{ Session::get('message') }}");
@endif这是css:
@section('vendor-style')
{{-- vendor css files --}}
<link rel="stylesheet" href="{{ asset('vendors/css/extensions/toastr.css') }}">
@endsection
@section('page-style')
{{-- Page Css files --}}
<link rel="stylesheet" href="{{ asset('css/plugins/extensions/toastr.css') }}">
@endsection和js文件:
@section('vendor-script')
{{-- vendor files --}}
<script src="{{ asset('vendors/js/extensions/toastr.min.js') }}"></script>
@endsection
@section('page-script')
{{-- Page js files --}}
<script src="{{ asset('js/scripts/extensions/toastr.js') }}"></script>
@endsection这些文件运行得很好。谢谢你的帮助!
发布于 2020-10-26 16:19:26
因为它是一个javascript库,所以您需要将以下代码放入<script>标记中
@if(Session::has('message'))
toastr.info("{{ Session::get('message') }}");
@endif至
@if(Session::has('message'))
<script>
toastr.info("{{ Session::get('message') }}");
</script>
@endif如果仍然不工作,则表示它没有触发您的代码,因此您可以这样做
@if(Session::has('message'))
<script>
$(function(){
toastr.info("{{ Session::get('message') }}");
})
</script>
@endif加载页面后,此代码将触发此代码
发布于 2021-10-28 17:48:45
我为tall stack (Laravel 8)创建了一个包,并将不断更新它。请随时查看:
https://stackoverflow.com/questions/64533501
复制相似问题