这是我的 AdsController.php
public function save(Request $request)
{
$this ->validate($request,[
'object'=>'required',
'description'=>'string',
]);
$ads = new Ad;
$current_user=Auth::user();
$ads->object = $request->input('object');
$ads->description = $request->input('description');
$ads->save();
$users = User::where(("id","!=",$current_user->id ) || ("admin","=",1 ))->get();
foreach ($users as $user) {
$user->notify(new NewAd($current_user, $ads));
}
return redirect('listads') ;
}
我想仅向管理员发布广告,但我有错误
请帮帮我
答案 0 :(得分:0)
您的查询构建器出了一个简单的错误,条件应该链接如下:
$users = User::where('id', '<>', $current_user->id)->where('admin', 1)->get();
答案 1 :(得分:0)
使用像这样的条件
$users = User::where("id","!=",$current_user->id)
->orWhere("admin",1 )->get();