Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jim1506's avatar

Overriding verification for delete

0 down vote favorite

I have a table Languages with a language field and an image field. the CRU of CRUD is fine but the delete is firing the default validation. I have defined two validation files in Requests. One is AddNewLanguageRequest which contains:

public function rules() { return [

            'language' => 'required|max:255|min:5',
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'

}

and the other is EditLanguageRequest which contains

public function rules() { return [

        'language' => 'required|max:255|min:5',
        'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'

    ];
}  

I have a form which shows the language and the image to be deleted and as confirm button and so this form calls a route:

{!! Form::open( array('url'=>'deletelanguage/'.$lang->id)) !!}

The route calls the LanguageController

public function delete(Requests\EditLanguageRequest $request){ //is there an image? If so delete it $lang = Language::find($request->id); if (isset($lang->image)) { if (Storage::exists($lang->image) ) {Storage::delete($lang->image);} } $lang->delete(); }

When I try it out I get a validation failure from the EditLanguageRequest.

How can I "turn off" validation for the delete action?

0 likes
2 replies
usama.ashraf's avatar

Just remove the EditLanguageRequest type-hint from the method signature.

public function delete(Request $request)
{ 
         //is there an image? If so delete it 
          $lang = Language::find($request->id); 
              if (isset($lang->image)) { 
            if (Storage::exists($lang->image) ) {
                Storage::delete($lang->image);
            } 
        } 
        $lang->delete();
 }
jim1506's avatar

Thanks. What a plonker I am. Well I am new to Laravel....Thanks again

Please or to participate in this conversation.