I have a button to remove a registration type, but the user should only be allowed to remove a registration type if there are no participant registered in that registration type, that is if there are no participants associated with that registration type.
But its not working with code below, it appears:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.registration_registration_types' doesn't exist (SQL: select registrations
.*, registration_registration_types
.registration_type_id
as pivot_registration_type_id
, registration_registration_types
.registration_id
as pivot_registration_id
from registrations
inner join registration_registration_types
on registrations
.id
= registration_registration_types
.registration_id
where registration_registration_types
.registration_type_id
= 3)
So I have this HTML that has the link to remove the registration type that when is clicked it shows a modal so the user confirm if he wants or no remove the registration type:
@foreach($registrationType as $rtype)
<div class="form-check">
<input
{{ (old('radiobutton') && old('radiobutton') == $rtype->id) ? 'checked' : '' }}
class="form-check-input radio" type="radio" name="radiobutton"
value="{{ $rtype->id }}" id="{{$rtype->id}}">
<label class="form-check-label" for="exampleRadios1">
{{$rtype->name}} <a data-toggle="modal" class="btn btn-sm btn-outline-light-gray ml-4"
data-target="#removeRtype">
<i class="fa fa-times" aria-hidden="true"></i> Remove</a>
</label>
</div>
<div class="modal fade bd-example-modal-lg" id="removeRtype" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Remove registration type</h5>
<button type="button" class="close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container">
<div class="row d-flex justify-content-center">
<p>Remove Registration type?</p>
<button class="btn btn-outline-primary" id="cancel_remove" href="#" data-dismiss="modal">No</button>
<a class="btn btn-primary ml-2" id="confirm_remove"
href="{{route('rtype.remove', ['rtypeID' => $rtype->id])}}">Yes</a>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="close_login_modal" class="btn btn-primary"
data-dismiss="modal">Close
</button>
</div>
</div>
</div>
</div>
@endforeach
And the method to remove the registration type:
public function destroy($rtypeID)
{
$rtype = RegistrationType::findOrFail($rtypeID);
$registrationsCount = $rtype->registrations->count();
dd($registrationsCount);
if ($registrationsCount == 0) {
$rtype->delete();
Session::flash('success', 'Registration type removed with success.');
return redirect()->back();
} else {
Session::flash('error', 'Is not possible to remove the registration type since there are already participants registered in it.');
return redirect()->back();
}
}
Route:
Route::get('conference/destroy/{rtypeID}/rtypes', [ 'uses' => 'RegistrationTypeController@destroy', 'as'=>'rtype.remove']);