Good day to all what happens is I have a problem when using a form:model since it tells me that there is no variable to pass and then reviewing the case is very rare.
this my controller.
public function store(Request $request)
{
$request->validate([
'name'=>'required']);
$role = Role::create(['name' => $request->name]);
// actualiza los permisos / sincroniza los permisos
$role->permissions()->sync($request->permissions);
return redirect()->route('roles.edit',$role)->with('info','el rol se creo con exito');
}
and this the variable with dd($role)
but when i see the dd in the form:model i can see this , the variable is not the same
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
{!! Form::model($role,['route' => ['roles.update',$role],'method'=> 'put', 'class' => 'm-8 item-center']) !!}
<div class="form-group">
{!! Form::label('name','Nombre del rol')!!}
{!! Form::text('name',null,['class' => 'form-control block mt-1 w-full','placeholder' => 'ingrese su nuevo rol'])!!}
</div>
<h2 class="h3 mt-3 mb-3">Lista de permisos</h2>
<div class="mb-3">
<label class="mb-3">
{!! Form::checkbox ('selectall',null,null,['class'=> 'mr-1','id' => "selectall"])!!}
Seleccionar todos los permisos
</label>
</div>
@foreach ($permisos as $item)
<div>
<label >
{!! Form::checkbox ('permisos[]',$item->id,null,['class'=> 'mr-1 permisos'])!!}
{{$item->description}}
</label>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$("#selectall").on("click", function() {
$(".permisos").prop("checked", this.checked);
});
// if all checkbox are selected, check the selectall checkbox and viceversa
$(".permisos").on("click", function() {
if ($(".permisos").length == $(".permisos:checked").length) {
$("#selectall").prop("checked", true);
} else {
$("#selectall").prop("checked", false);
}
});
</script>
@endforeach
{!! Form::submit('Editar rol',['class' => ' mt-3 inline-flex items-center justify-center px-4 py-2 bg-red-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-red-500 focus:outline-none focus:border-red-700 focus:ring focus:ring-red-200 active:bg-red-600 disabled:opacity-25 transition'])!!}
{!! Form::close() !!}
</div>
</div>
</div>
thank you , if someone help me to solve this problem