2017-08-10 8 views
0

存在しないエラーは言う:。(1/1)ReflectionExceptionエラークラスのApp のHttp リクエストは、私がlaravelに新しいですし、私がログインしているユーザーのプロファイルにアップデートしようとしている

クラスApp \ Http \ Request \ UpdateApplicantRequestは存在しません

しかし、私はそれをコントローラの上部にインポートしました。ここで

HomeController.php

<?php 

namespace App\Http\Controllers\Applicant; 

use Illuminate\Http\Request; 
use App\Http\Requests; 
use App\Http\Controllers\Controller; 
use App\Repositories\ApplicantsRepository; 
use Flash; 
use Response; 
use App\Models\Applicant; 
use App\Http\Request\UpdateApplicantRequest; 


class HomeController extends Controller 
{ 

    private $applicantRepository; 
    /** 
    * Create a new controller instance. 
    * 
    * @return void 
    */ 
    public function __construct(ApplicantsRepository $applicantRepo) 
    { 
     $this->middleware('applicant'); 
     $this->applicantsRepository = $applicantRepo; 
    } 

    /** 
    * Show the application dashboard. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     return view('applicant-dashboard.home'); 
    } 

    public function edit($id) 
    { 
     //$applicant = $this->applicantRepository->findWithoutFail($id); 
     $applicant = Applicant::where('id',$id)->get()->last(); 

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

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

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

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

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

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

     $input = $request->all(); 

     $applicant = $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.home')); 
    } 
} 

は私のルートのコードです:

Route::get('/edit/{id}', '[email protected]')->name('applicant.edit'); 
    Route::patch('/put', '[email protected]')->name('applicant.update'); 

と私のブレード・ファイル内のコード:

@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 

私が探しています助けて。 ありがとうございました。

+0

use App\Http\Requests\UpdateApplicantRequest; 

その後、からフォームを変更'UpdateApplicantRequest.php'ファイルに名前空間を定義しますか?そしてそれはどこに置かれますか? –

+0

App \ Http \ Requestsのような名前空間。 –

+0

私はすでにそれを解決しました。しかし問題は、私が提出するか、更新ボタンを保存するボタンを押すときです。ブラウザをリフレッシュするだけです。 –

答えて

1

まず、UpdateApplicantRequestの間違った名前空間を使用します。

変更:

use App\Http\Request\UpdateApplicantRequest; 

へ:

{!! Form::model($applicant, ['route' => ['applicant.update', $applicant->id], 'method' => 'patch']) !!} 

    @include('applicant-dashboard.fields') 

{!! Form::close() !!} 

へ:どうやっ

{!! Form::model($applicant, ['route' => ['applicant.update', $applicant->id], 'method' => 'post']) !!} 

    {!! method_field('patch') !!} 
    @include('applicant-dashboard.fields') 

{!! Form::close() !!} 
+0

ありがとう!エラーは消えましたが、nothingsのようにページを更新するだけで問題が発生しました。 –

+0

私の答えをよく見てください。 –

+0

すでに動作しています!ありがとうbtw :) –

関連する問題