php files that represents the data needed to be added in the Pivot Table.
First I have my Roles.blade.php which contains the Roles of the Users:
@extends('layouts.loggedin')
@section('content')
<h1 class="text-center">Members Reports</h1>
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card">
<div class="card-header">Users</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Role</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($roles as $role)
<tr>
<td>{{$role->id}}</td>
<td>{{$role->name}}</td>
<td>
@can('view', \App\Model::class)
<a href="/model/index">
<button type="submit" class="btn btn-primary">Edit</button>
</a>
@endcan
<button type="submit" class="btn btn-primary">Delete</button></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
@endsection
Second I have my The blade.php that is Linked to my Edit Button
@extends('layouts.loggedin')
@section('content')
<h1 class="text-center">Members Reports</h1>
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card">
<div class="card-header">Edit Abilities </div>
<div class="card-body">
<form class="" action="/members/update" method="post">
@csrf
@foreach ($models as $model)
<div class="form-check">
<label>{{$model->name}}</label>
@foreach ($abilities as $ability)
<div class="form-check">
<input type="checkbox" name="abilities[]" value="{{$ability->id}}">
<label>{{$ability->name}}</label>
</div>
@endforeach
</div>
@endforeach
<!-- @can('update', App\User::class) -->
<div class="form-group">
<button type="submit" name="add" class="btn btn-success float-right">Update Abilities</button>
</div>
<!-- @endcan -->
</form>
</div>
</div>
</div>
</div>
@endsection
I have a pivot table called ability_model that represents the ability ( view, edit, update, delete ) on each model (Question, Answer, User, Report) and I have another pivot table called ability_model_role that should represent the Role ( admin or user ) assigned to the ability on the model and that should be added from that form.