如何发送通知给具有不同成员角色的成员?

时间:2020-11-05 17:22:51

标签: laravel

我想立即按标题中的要求提问。
我有这样的控制器:

public function store(Request $request)
{
    //

    $this->validate($request, [
        'status'=> 'required|min:1|max:2',
        'subject' => 'required|min:10|max:255',
        'body' => 'required|min:10|max:100000'
    ]);
    if ($request->status == 1){
        $this->validate($request, [
            'email' => 'required|email',
        ]);
        $user = User::whereEmail($request->email)->firstOrFail();
        $notice = new Notice();
        $notice->user_id = $user->id;
        $notice->title = $request->subject;
        $notice->priority = $request->priority;
        $notice->body = $request->body;
        $notice->status = 0;

        if ($request->hasFile('featured')){
            $featured = $request->featured;
            $featured_new_name = time().$featured->getClientOriginalName();
            $featured->move('uploads/posts', $featured_new_name);
            $notice->file = 'uploads/posts/'. $featured_new_name;
        }
        $notice->save();
        session()->flash('message', "Send Message to ".$user->name." Successful!");
        Session::flash('type', 'success');
        Session::flash('title', 'Message Send Success!');
        return redirect()->route('adminMessage.create');
    }
    else {

        $users = User::all();

        if ($request->hasFile('featured')){
            $featured = $request->featured;
            $featured_new_name = time().$featured->getClientOriginalName();
            $featured->move('uploads/posts', $featured_new_name);
            $attachment = 'uploads/posts/'. $featured_new_name;
        }
        foreach ($users as $user){

            $notice = new Notice();
            $notice->user_id = $user->id;
            $notice->title = $request->subject;
            $notice->priority = $request->priority;
            $notice->body = $request->body;
            $notice->status = 0;

            if ($request->hasFile('featured')){
                $notice->file  = $attachment;
            }
            $notice->save();
        }
        session()->flash('message', "Send Message to all Users Successful!");
        Session::flash('type', 'success');
        Session::flash('title', 'Message Send Success!');
        return redirect()->route('adminMessage.create');
    }
}

我在此字段中有2个状态:
对于状态1,我发送了选定的成员(仅一个)
对于状态2,我发送给所有用户使用$user= User::all();

所以我需要与Membership_role发送通知相关的帮助
我有会员表,例如:

=========================
| id |  name  |  count  |
-------------------------
|  1 |  free  |  200    |
|  2 |  free  |  200    |
|  3 |  free  |  200    |
|  4 |  free  |  200    |

如何向会员ID:2,3,4

发送消息

1 个答案:

答案 0 :(得分:1)

如果它是impl<S, T> MyCalculate for MyDrawing<T> where T: TheirShadow<Output=S> + MyCenter<Input=S> 模型的属性,则可以使用查询来查找所需的一个或多个用户。

Tasks
    |-TaskId
    |-SourceDatabase (FK to the Databases table)
    |-TargetDatabase (FK to the Databases table)

Databases
    |-DatabaseId (PK)
    |-Other database details.