I am stuck about a problem, in fact I want to create a Role
and a Permission
. In my form.
I added the informations for each fields.
I have an error message:
ErrorException in RoleController.php line 44: Invalid argument supplied for foreach()
Here is a party of my code, I don't see the error??
public function store(Request $request)
{
$role=Role::create($request->except(['permission','_token']));
foreach ($request->permission as $key=>$value){
$role->attachPermission($value);
}
return redirect()->route('role.index')->withMessage('role created');
}
My form Role create
@extends('admin.layout.admin')
@section('content')
<h3>Create Roles</h3>
<form action="" method="post" role="form">
<div class="form-group">
<label for="name">Name of role</label>
<input type="text" class="form-control" name="name" id="" placeholder="Name of role">
</div>
<div class="form-group">
<label for="display_name">Display name</label>
<input type="text" class="form-control" name="display_name" id="" placeholder="Display name">
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" name="description" id="" placeholder="Description">
</div>
<div class="form-group text-left">
<h3>Permissions</h3>
@foreach($permissions as $permission)
<input type="checkbox" name="permission[]" value="" > <br>
@endforeach
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
@endsection
My form - Role index
@extends('admin.layout.admin')
@section('content')
<h3>Roles</h3>
<a class="btn btn-success" href=""> Create Role</a>
<table class="table">
<tr>
<th>Name</th>
<th>Display Name</th>
<th>Description</th>
<th>Action</th>
</tr>
@forelse($roles as $role)
<tr>
<td></td>
<td></td>
<td></td>
<td>
<a class="btn btn-info btn-sm" href="">Edit</a>
<form action="" method="POST">
<input class="btn btn-sm btn-danger" type="submit" value="Delete">
</form>
</td>
</tr>
@empty
<tr>
<td>No roles</td>
</tr>
@endforelse
</table>
@endsection
Thank you for your help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire