Database Queries
Deleting rows with foreign key constraints
Figure out all the relationships of the table of the row you are trying to delete (go to model_name.php and check for belongsToMany, HasMany, etc.)
Create a delete helper function in model_name.php and use
detach()
anddelete()
as necessarypublic function delete() { $this->grants()->detach(); $this->fippaImports()->detach(); $this->documents()->delete(); parent::delete(); }
Call this function in the controller
public function destroy(FippaTracking $fippaTracking) { $fippaTracking->delete(); return redirect() ->route('fippa_trackers') ->withSuccess('Fippa Tracker successfully deleted.'); }
Last updated
Was this helpful?