noblemfd
1 month ago

How to re-write checkbox Form Action

Posted 1 month ago by noblemfd

Initially I have this view blade:

{!! Form::open(array('route' => 'roles.store','method'=>'POST')) !!}
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group">
        <strong>Name:</strong>
        {!! Form::text('name', null, array('placeholder' => 'Name','class' => 'form-control')) !!}
    </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group">
        <strong>Permission:</strong>
        <br/>
        @foreach($permission as $value)
            <label>{{ Form::checkbox('permission[]', $value->id, false, array('class' => 'name')) }}
            {{ $value->name }}</label>
        <br/>
        @endforeach
    </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
    <button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}

Now I changed the code to this:

    <form action="{{ route("admin.roles.store") }}" method="POST" enctype="multipart/form-data">
        @csrf
        <div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
            <label for="title">{{ trans('global.role.fields.title') }}*</label>
            <input type="text" id="title" name="name" class="form-control" value="{{ old('name', isset($role) ? $role->name : '') }}">
            @if($errors->has('title'))
                <p class="help-block">
                    {{ $errors->first('name') }}
                </p>
            @endif
            <p class="helper-block">
                {{ trans('global.role.fields.title_helper') }}
            </p>
        </div>
  <input type="checkbox" id="checkAll" > Check All
   <hr />
  <div class="col-xs-12">
   <div class="row">
    <div class="col-xs-12">
       <strong>Permission:</strong>
    </div>
   </div>
  <div class="row">

  @foreach($permission as $value)
     <div class="form-group col-md-4">
        <label>
           {{ Form::checkbox('permission[]', $value->id, false, array('class' => 'name')) }}
           {{ $value->name }}
        </label>
     </div>
  @endforeach
 </div>
</div>
        <div>
            <input class="btn btn-primary" type="submit" value="{{ trans('global.save') }}">
        </div>
    </form>

Now the challenge I have is that I don't know how to re-write

           {{ Form::checkbox('permission[]', $value->id, false, array('class' => 'name')) }}
           {{ $value->name }}

in

  @foreach($permission as $value)
     <div class="form-group col-md-4">
        <label>
           {{ Form::checkbox('permission[]', $value->id, false, array('class' => 'name')) }}
           {{ $value->name }}
        </label>
     </div>
  @endforeach

to suite

<form action="{{ route("admin.roles.store") }}" method="POST" enctype="multipart/form-data">

instead of

{!! Form::open(array('route' => 'roles.store','method'=>'POST')) !!}

How do I achieve this?

Please sign in or create an account to participate in this conversation.