Php 如何在Laravel中向当前未登录的用户发送通知?

Php 如何在Laravel中向当前未登录的用户发送通知?,php,mysql,laravel,laravel-notification,Php,Mysql,Laravel,Laravel Notification,我正在构建一个求职类型的应用程序。有两种类型的用户,求职者和雇主,每个人都有自己的角色。当雇主登录时,他可以浏览候选人的个人资料并请求面试。他可以为时间和日期选择两个选项,然后单击“发送”。当该特定用户登录时,我希望在页面顶部显示带有钟形图标的通知,通知应显示“您已收到面试请求!”。然后,当他们单击它或转到管理面板上的通知部分时,它将显示雇主信息“嗨,用户名,ABC公司对您的个人资料感兴趣,并希望安排您参加面试。”以及2个日期和时间选项。求职者选择日期和时间选项1,单击发送,然后雇主收到求职者的

我正在构建一个求职类型的应用程序。有两种类型的用户,求职者和雇主,每个人都有自己的角色。当雇主登录时,他可以浏览候选人的个人资料并请求面试。他可以为时间和日期选择两个选项,然后单击“发送”。当该特定用户登录时,我希望在页面顶部显示带有钟形图标的通知,通知应显示“您已收到面试请求!”。然后,当他们单击它或转到管理面板上的通知部分时,它将显示雇主信息“嗨,用户名,ABC公司对您的个人资料感兴趣,并希望安排您参加面试。”以及2个日期和时间选项。求职者选择日期和时间选项1,单击发送,然后雇主收到求职者的通知。他们将以这种方式进行沟通,直到双方就安排面试的日期和时间达成一致。所以我想要两个通知。1当面试请求发送给应聘者时,第二个是当应聘者选择对他有利的日期和时间并将请求发送回雇主时。我知道当用户登录时如何发送通知,但我缺少一些关于如何向未登录的用户发送通知的信息。这两种类型的用户都存储在my users表中,只是角色不同

job_seeker_profile.blade.php文件:

{!! Form::open(['method'=>'POST', 'action'=>'AdminEmployerInterviewRequestsController@store', 'files'=>true, 'style'=>'width: 100%;']) !!}

<div class="form-group">
    <div class="input-group date" id="datetimepicker1" data-target-input="nearest">
        {!! Form::text('date_time1', null, ['class'=> $errors->first('date_time1') ? 'border-danger form-control datetimepicker-input' : 'form-control datetimepicker-input', 'data-target'=>'#datetimepicker1']) !!}
        <div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
        </div><br>
    </div>
    <small class="text-danger">{{ $errors->first('date_time1') }}</small>
</div>
<div class="col">

</div>

<div class="form-group">
    <div class="input-group date" id="datetimepicker2" data-target-input="nearest">
        {!! Form::text('date_time2', null, ['class'=> $errors->first('date_time2') ? 'border-danger form-control datetimepicker-input' : 'form-control datetimepicker-input', 'data-target'=>'#datetimepicker2']) !!}
        <div class="input-group-append" data-target="#datetimepicker2" data-toggle="datetimepicker">
            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
        </div><br>
    </div>
    <small class="text-danger">{{ $errors->first('date_time2') }}</small>
</div>

<div class="form-group">
    {!! Form::hidden('user_id', Auth::user()->id, ['class'=>'form-control']) !!}
</div>

<div class="form-group">
    {!! Form::hidden('job_seeker_profile_user_id', $jobSeekerProfile->id, ['class'=>'form-control']) !!}
</div>

<div class="form-group">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    {!! Form::submit('Send Interview Request', ['class'=>'btn btn-primary float-right']) !!}
</div>
<br><br><br><br>

{!! Form::close() !!}
public function store(EmployerInterviewCreateRequest $request)
{
    $input = $request->all();

    $user = Auth::user();

    $JobSeekerProfile = JobSeekerProfile::all();

    $user->interviewRequestsSent()->create($input);
    $user->interviewRequestsReceived()->create($input);

    $user->notify(new InterviewRequestSent());

    $JobSeekerProfile->notify(new InterviewRequestReceived());

    return redirect('/admin/employer/interviews');

}
但是当我打电话给

$JobSeekerProfile->notify(new InterviewRequestReceived());
它给了我这个错误:

Method Illuminate\Database\Eloquent\Collection::notify does not exist.

是否可以在采取操作后向其他用户发送通知?

现在不可能。只有登录的用户才能收到通知。我已经发送了几张关于此的通知单,您的错误是因为您正在将每个
JobSeekerProfile
拉入一个集合,然后尝试调用集合上的
notify()
。由于您正在提交ID,因此只需使用它来构建一个实例并通知它

public function store(EmployerInterviewCreateRequest $request)
{
    $input = $request->all();

    $user = Auth::user();

    $JobSeekerProfile = JobSeekerProfile::find($request->job_seeker_profile_user_id);

    $user->interviewRequestsSent()->create($input);
    $user->interviewRequestsReceived()->create($input);

    $user->notify(new InterviewRequestSent());

    $JobSeekerProfile->notify(new InterviewRequestReceived());

    return redirect('/admin/employer/interviews');

}

“notify not found on this”或“notify not found on this not super help…”。。。您能提供导致错误的代码和实际的错误消息吗?请编辑您的问题以包含此信息。我对其进行了编辑。现在看看我的控制器和我收到的错误信息。有没有其他方法来实现我想要的?