Laravel를 사용하여 경로 URI의 노선 매개 변수를 누락?

라이언 자루 :

나는 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!');

}

이건 내 오류입니다 :

에 필요한 매개 변수를 누락 [경로 : admin.employer.post-A-job.show.send 프로파일] [URI : 관리자 / 구직자 / 검색 / 고용주 / {employerId} / 포스트 - 직무 / {jobPostId} / 송신 프로파일]. (보기 : /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">&times;</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_idsend_profiles테이블 후 고용주에게 알림을 보낼 수 있습니다.

miken32 :

귀하의 경로는 특정 매개 변수를 포함하는 URL에 GET 요청을 지정합니다 :

/admin/job-seeker/search/employer/{employerId}/post-a-job/{jobPostId}/send-profile

귀하의 양식을 사용하는 AdminEmployerJobPostsController@sendProfile작업으로, 이것은 무엇을 Laravel 생각하는 가장 적합한 경로 목록을 검색하고 선택하여 URL로 변환됩니다. 당신이 채우기 위해 아무것도 통과하지 않았으므로 employerIdjobPostId매개 변수를 URL이 생성 될 때이 오류가 나타나는 것입니다.

당신이 URL이 생성받을 수있는 경우에도 양식이 GET 경로에 POST 요청을 전송하기 때문에, 당신은 문제가있는 것입니다.

당신이해야 할 것은 당신이 새로운 컨트롤러 메소드를 가리키는 POST 경로를 가지고 있는지 확인합니다. 컨트롤러 방법은 일반적으로 받아 들일 것입니다, 그래서 당신은 URL에이 경로에 어떤 매개 변수를 전달하지 않습니다 Request매개 변수로 객체를. 당신이해야 할 두 번째 것은 더 정확하게 양식의 대상을 지정합니다. 대신 추측 만들기의 경로 이름을 전달합니다.

public function sendProfile(Request $request)
{
    // you get this here so no need to pass it in the form
    $user = Auth::user();

    // your relations should be set up so you don't need to do this:
    // $jobSeekerProfile = JobSeekerProfile::all()->where('user_id', $user->id)->first();
    // instead do this:
    $jobSeekerProfile = $user->jobSeekerProfile();

    // a simple find is much neater than what you had
    $employerProfile = EmployerProfile::find($request->job_seeker_profile_user_id);

    // not sure why this is here?
    $jobPosts = JobPosts::all();

    // also your form isn't passing a job post ID
    $jobPost = JobPosts::findOrFail($request->jobPostId);

    // ??? creating an empty something?
    $user->sendProfile()->create();

    $employerProfile->notify(new SendProfile());

    return back()->with('send-profile', 'Your Profile has been sent!');

}

추천

출처http://43.154.161.224:23101/article/api/json?id=294416&siteId=1