【发布时间】:2020-06-25 20:14:33
【问题描述】:
我正在尝试创建 Laravel 通知。我创建了一个名为send_profiles 的表。当候选人登录并搜索工作时,他可以将他的工作资料发送给雇主。所有这些数据都在一个名为job_seeker_profiles 的表中。我正在开发求职类型的应用程序。
我创建了一个名为SendProfile.php 的新通知类:
public function toDatabase($notifiable)
{
$user = Auth::user();
return [
'user_id' => Auth::user()->id,
'employer_profile_id' => DB::table('send_profiles')->where('user_id', $user->id)->orderBy('id', 'desc')->offset(0)->limit(1)->get('employer_profile_id'),
];
}
我不知道最好的方法,但无论如何这是我的路线。 web.php:
Route::get('/admin/job-seeker/search/employer/{employerId}/post-a-job/{jobPostId}/send-profile', 'AdminEmployerJobPostsController@sendProfile')->name('admin.employer.post-a-job.show.send-profile')->middleware('verified');
AdminEmployerJobPostsController.php:
public function sendProfile($employerId, $jobPostId)
{
$user = Auth::user();
$jobSeekerProfile = JobSeekerProfile::all()->where('user_id', $user->id)->first();
$employerProfile = EmployerProfile::limit(1)->where('id', $employerId)->get();
$jobPosts = JobPosts::all();
$jobPost = JobPosts::findOrFail($jobPostId);
$user->sendProfile()->create();
$employerProfile->notify(new SendProfile());
return back()->with('send-profile', 'Your Profile has been sent!');
}
这是我的错误:
缺少 [Route: admin.employer.post-a-job.show.send-profile] [URI: admin/job-seeker/search/employer/{employerId}/post-a-job/{ jobPostId}/send-profile]。 (查看:/Applications/XAMPP/xamppfiles/htdocs/highrjobs/resources/views/admin/employer/post-a-job/show.blade.php)
show.blade:
@extends('layouts.admin')
@section('pageTitle', 'Create a User')
@section('content')
@include('includes.job_seeker_search_employers')
<!-- The Modal -->
<div class="modal" id="myModal5">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">{{ $jobPost->job_title }}</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<h5>{{ $jobPost->job_description }}</h5>
</div>
<!-- Modal footer -->
<div class="modal-footer">
{!! Form::open(['method'=>'POST', 'action'=>'AdminEmployerJobPostsController@sendProfile', 'files'=>true, 'style'=>'width: 100%;']) !!}
<div class="form-group">
{!! Form::hidden('user_id', Auth::user()->id, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::hidden('employer_profile_user_id', $employerProfile->id, ['class'=>'form-control']) !!}
</div>
<div class="row">
<div class="col">
{!! Form::button('Back', ['class'=>'btn btn-danger btn-block float-left', 'data-dismiss'=>'modal']) !!}
</div>
<div class="col">
{!! Form::submit('Send Profile', ['class'=>'btn btn-primary btn-block float-right']) !!}
{!! Form::close() !!}
</div>
</div>
<br><br><br><br>
</div>
</div>
</div>
</div>
@stop
如果我删除表单,我至少不会收到错误消息。所以我实际上认为表单存在问题。
明确地说,我只想将user_id 和employer_profile_id 插入send_profiles 表中,然后向雇主发送通知。
【问题讨论】:
-
您的问题与通知无关,而是关于该主题:为什么在创建通知时将内容保存到数据库而不是将它们传递给通知?在基本代码中发送通知见this example,然后看看the notification class如何处理。
-
你是说所有通知数据都应该只在通知表中?
-
我是说您可以在创建通知时直接将内容传递给通知,而不是进行更多的数据库查找。您确实应该以尽量减少数据库访问为目标,因此如果您已经拥有信息,请使用它。
-
是的,这就是为什么我只想传递一个user_id 和一个employer_profile_id,这样我就知道哪个应聘者向哪个雇主发送了表单请求。
-
我尝试在通知上观看 YouTube 视频。我对这个话题感到很困惑。
标签: php mysql laravel routes laravelcollective