简体   繁体   中英

Laravel 5.4 How to update profile of applicant guest that is logged in

I am new to laravel and I want to let the user update his/her profile when logged in. I want to get the ID of the user when updating his/her profile but when I click on the edit view to pass the data using the id I got this error:

 (1/1) ErrorException Missing argument 1 for App\\Http\\Controllers\\Applicant\\HomeController::edit() 

Here is the code to my controller:

public function edit($id)
    {
        $applicant = $this->applicantRepository->findWithoutFail($id);

        if (empty($applicant)) {
            Flash::error('Applicant');

            return redirect(route('applicant.home'));
        }

        return view('applicant-dashboard.edit')->with('applicants', $applicant);
    }

    public function update($id, UpdateApplicantRequest $request)
    {
        $applicant = $this->applicantRepository->findWithoutFail($id);

        if (empty($applicant)) {
            Flash::error('Applicant not found');

            return redirect(route('applicant.index'));
        }

        $input = $request->all();

        $cashier = $this->applicantRepository->update([
            'name' => $input['name'],
            'email' => $input['email'],
            'password' => bcrypt($input['password']),
            'address' => $input['address'],
            'cellphone_no' => $input['cellphone_no']], $id);

        Flash::success('Profile updated successfully.');

        return redirect(route('applicant.index'));
    }

Here is the code in my routes file:

Route::get('/edit', 'HomeController@edit')->name('applicant.edit');

Here is the code in my blade file:

@extends('layouts.app')

@section('content')
    <section class="content-header">
        <h1>
            Applicant Profile
        </h1>
   </section>
   <div class="content">
       {{-- @include('adminlte-templates::common.errors') --}}
       <div class="box box-primary">
           <div class="box-body">
               <div class="row" style="padding-left: 20px">
                   {!! Form::model($applicant, ['route' => ['applicant.update', $applicant->id], 'method' => 'patch']) !!}

                        @include('applicant-dashboard.fields')

                   {!! Form::close() !!}
               </div>
           </div>
       </div>
   </div>
@endsection

在此处输入图片说明

您需要将id传递到您的路线中:

Route::get('/edit/{id}', 'HomeController@edit')->name('applicant.edit');

您将ID传递到web.php中:

Route::get('edit/{ID}', 'HomeController@edit')->name('applicant.edit');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM