I have two tables with one to many relationship, "Locations" and "Devices", the problem arises when trying to delete a "location" that has a "device" related, I need you to show a notice that says that the deletion was not made and not the error SQLSTATE [23000], is it possible to capture the error? this is what I have so far.
public function destroy(Location $location)
{
try {
//Eliminar registro
$location->delete();
} catch (Illuminate\Database\QueryException $e) {
$status = 'Registro relacionado, imposible de eliminar';
}
//Retornar vista
return redirect()->route('locations.index')
->with('status', $status);
}