I'm doing a error exception where display a modal popup when fail to delete an entry due to parent constrain
Controller :
public function deleteUnitType(Request $request, $proj_id)
{
$id = $request->id;
$unit_types = UnitType::where('id', $id);
$floors = UnitTypeFloor::where('unit_type_id', $id)->get();
if(count($floors) != 0){
return redirect()->route('dev-admin.projects.unit-types.index', ['unit_types' => $unit_types, 'proj_id' => $proj_id, 'floors' => $floors])->with('failed', 'Unit Type failed to delete due to existing floor plan.');
} else {
// $unit_types->delete();
return redirect()->route('dev-admin.projects.unit-types.index', ['unit_types' => $unit_types, 'proj_id' => $proj_id])->with('status', 'Unit Type is successfully deleted.');
}
}
HTML :
<div class="col-12">
@if (session('status'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
@elseif (session('failed'))
<div class="modal fade" id="unit-type-notification-modal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<p></p>
<ul>
@foreach($floors as $floor)
<li></li>
@endforeach
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endif
</div>
$( document ).ready(function() {
@if (session('failed'))
$('#unit-type-notification-modal').modal('show');
@endif
});
The modal popup and everything but for some reason it cannot find my $floor
variable, it says :
Undefined variable: floors
but when I dd it on my controller, the data exist
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire