misterdebug / crud-generator-laravel

Create a Laravel 10 CRUD in a few seconds
315 stars 44 forks source link

Wishlist: relationships generate select controls #25

Closed baradhili closed 1 year ago

baradhili commented 1 year ago

So that the CRUD is pretty usable out of the box

misterdebug commented 1 year ago

You're talking about which type of select controls? Can you give me an example? Thx

baradhili commented 1 year ago

So if you login to http://demo-freelancer-crm.quickadminpanel.com/ and then visit http://demo-freelancer-crm.quickadminpanel.com/admin/projects/create you will notice the select control letting you link a project to a client

misterdebug commented 1 year ago

There is a javascript need and I don't want to force a javascript solution in the views generated (vanilla, react, vue ? Etc...)

baradhili commented 1 year ago

Just digging around in the quickadmin code.. ... Controller:-

public function create()
    {
        abort_if(Gate::denies('substance_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $tox_components = ToxComponent::pluck('amount', 'id');

        return view('admin.substances.create', compact('tox_components'));
    }

and view... (create.blade.php)

...
<div class="form-group">
    <label for="tox_components">{{ trans('cruds.substance.fields.tox_component') }}</label>
    <div style="padding-bottom: 4px">
        <span class="btn btn-info btn-xs select-all" style="border-radius: 0">{{ trans('global.select_all') }}</span>
        <span class="btn btn-info btn-xs deselect-all" style="border-radius: 0">{{ trans('global.deselect_all') }}</span>
    </div>
    <select class="form-control select2 {{ $errors->has('tox_components') ? 'is-invalid' : '' }}" name="tox_components[]" id="tox_components" multiple>
        @foreach($tox_components as $id => $tox_component)
            <option value="{{ $id }}" {{ in_array($id, old('tox_components', [])) ? 'selected' : '' }}>{{ $tox_component }}</option>
        @endforeach
    </select>
    @if($errors->has('tox_components'))
        <div class="invalid-feedback">
            {{ $errors->first('tox_components') }}
        </div>
    @endif
    <span class="help-block">{{ trans('cruds.substance.fields.tox_component_helper') }}</span>
</div>
...

So you don't need to use JS

misterdebug commented 1 year ago

select2 is js ahah and to do this you need to know which column you will display in the select