mardi 17 juillet 2018

Validation on update Laravel

Good Day,

I'm really new to laravel and having fun using it until I encounter one problem that really gives me pain in programming, It's the validation redirect during update method. It gives me an error

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message

The program is about denying a purchase request and I want the denial to write a note abt the reason of it's denial, that field should not be empty, I can validate it but my problem is the error during redirection.

here is the form for the deny.blade.php

 {!!Form::open(['action'=>['prInitialApprovalController@update',$post->id],',method'=>'POST', 'class'=>'pull-right'])!!}
                <div class="form-group">
                        
                        
                    </div>    
                
                
                
                <a href="/pr_approval" class="btn btn-dark">Return</a>
                {!!Form::close()!!}

and here is the update method on the controller

public function update(Request $request, $id)
{
//update category
 $post = prModel::find($id);

 if($request->input('denied') == '11'){
    $validator = Validator::make($request->all(), [

        'denyNote' => 'required',
    ]);

    if ($validator->fails()) {

                    return redirect()->action(
                        'prInitialApprovalController@deny', $id
                    )->withErrors($validator);
                 }else{


        $post->pr_status = '11';
        $post->deny_reason = $request->input('denyNote');
        $post->save();
        return redirect('/pr_approval')->with('success', 'Purchase Request Denied');
        }
    }
 }

Here is my web route

Route::put('pr_approval/{id}/deny', 'prInitialApprovalController@deny');
Route:: Resource('/pr_approval', 'prInitialApprovalController');
Auth::routes();

Please help I'm really stuck on this for like days. I'm using laravel 5.6

Thank you




Aucun commentaire:

Enregistrer un commentaire