我正在尝试执行通知功能,系统应在该功能中向下拉列表中的所选用户(carOwnerName)发送通知。
carOwnerName是一个用户ID,在用户从下拉列表中选择后将存储在mysql中
这里有一些代码
通知(carNotify)
class carNotify extends Notification
{
protected $validations;
public function __construct($validations)
{
$this->validations = $validations;
}
public function via($notifiable)
{
return ['database'];
}
public function toArray($notifiable)
{
return [
'User_id' => $this->validations->carOwnerName,
];
}
}
控制器
public function update(Request $request, $id)
{
$validations = Cars::findOrFail($id);
$validations->carOwnerDept = $request->input('carOwnerDept');
$validations->carOwnerName = $request->input('carOwnerName');
$input = $request->all();
$validations->fill($input)->save();
$user = $validations->carOwnerName = $request->carOwnerName;
$user->sendNotification($validations);
Session::flash('flash_message', 'News updated successfully!');
return Redirect::to('/validateCars')->with('success', "Successfully Validated !");
汽车模型
public function sendNotification($validations)
{
$this->notify(new carNotify($validations));
}
浏览
<li class="nav-item dropdown">
<a class="nav-link " data-toggle="dropdown" href="#"><i class="fa fa-bell"></i>
@foreach (Auth()->user()->unreadNotifications as $notification)
@if($notification->data['cars']['carOwnerName'] == auth()->user()->id)
<span class="badge badge-danger">{{ Auth()->user()->unreadnotifications->count()}}</span></a>
@else
<span class="badge badge-primary">0</span></a>
@endif
@endforeach
这是我第一次执行laravel通知功能。有什么建议吗?
问题已解决,带有以下代码:)
User::find($validations->carOwnerName)->notify(new carNotify($validations));