【发布时间】:2021-02-08 11:54:23
【问题描述】:
我刚刚在表单提交时添加了一个 toast,但它不起作用,我不明白这个问题。
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
这些文件工作正常。感谢您的帮助!
【问题讨论】:
-
还是不行!
-
你的head标签下是否加载了tosstr cdn?
-
是的,所有文件都正确连接
-
会话有消息?用
@if(Session::has('message')) alert("hello"); @endif检查它 -
没有警报没有显示
标签: php laravel laravel-blade laravel-8