mercredi 29 janvier 2020

laravel delete multiple record from different database at once

I want delete two record from different table with one delete function. however it is only deleting one of the record even though I passed two different Ids. this is my delete function

 public function delete($id){
   $user_id = auth() ->user()->id;
   $card =  Card::where('id', $id)->delete();
   $actCity = city::where('id', $id)->delete();

  return redirect('/home')->with('success', 'Post Removed');

this is my delete button

 @if (!empty($cardd && $actCity))
   {!!Form::open(['action'=>['PlanController@delete','id' =>$cardd[0], 'id'=>$actCity[0]],'method'=>'POST','class'=>''])!!}
   @endif
    
    {!! Form::submit('Delete', array(
        'class'   => 'btn btn-danger',
        'onclick' => "if( ! confirm('Are you sure you want to delete your 
 package?')){return false;}"
    )) !!}  {!! Form::close() !!}

my route

Route::delete('delete/{id}', 'PlanController@delete');


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire