Skip to content

How to add multi-value field? #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hondaman900 opened this issue Jan 4, 2018 · 6 comments
Open

How to add multi-value field? #151

hondaman900 opened this issue Jan 4, 2018 · 6 comments

Comments

@hondaman900
Copy link

I'm trying to make one of the user input form fields a drop-down options list. I can do this (add the HTML for the ) in the blade and have tried to have this modify the database data, to no avail. Can you recommend how to do this. I want to use this tool to accelerate a project that has many data input forms for the user, but need to be able to have the user select from drop-down options for some fields. Thanks in advance for your help.

@amranidev
Copy link
Owner

@hondaman900, thanks for submitting this issue.
If I understand your issue, you can create a new entity using scaffold-interface and link it to the user entity via One-To-Many relationship, all you have to do is:

  • Go to the interface.
  • While creating the new entity, make sure to link it with user's entity selecting the username through the interface.

This will generate (CRUD) for your new entity and generate user drop-down in create.blade.php so you can select a user while creating a record into the database (entity table).

Please check the following link scaffold-interface OneToMany.

@hondaman900
Copy link
Author

Thanks for the quick response. That's not exactly what I was trying to achieve. I was hoping that the generated data entry form could provide my user with a drop-down list of options for some fields, rather than having them type in entries that need to be one from a pre-determined set of values.

For instance, for a user entering their address they should be able to select a drop-down list of states to enter their state, rather then type in the state letters. It's a limited preset list and this avoids typo errors. I was hoping that in the blades for edit or create that I could simply code in a form element with pre-populated list of options, and have the result of the user's choice be recorded in the database and displayed as a regular field in the index and show blades.

@hondaman900
Copy link
Author

hondaman900 commented Jan 6, 2018

Update: I did get mostly success implementing a populated drop-down for a form field by replacing the blade form element with a , retaining the existing parameters and populating the options. There are some weird behaviors but I think I can sort them out. I did try to create an entity with a user drop-down as you suggested above and following your documentation, but the "Associate" button created provides the single option to select users but then gives a "page not found" error. Have to dig deeper into that to get it to work. From your comments I thought that the logged-in user could create records that wouldn't be available/visible to a different user. However, switching to a different user shows all records. All users see all records. Isn't isolating content owned by separate users not the default behavior or do I need to set that up somewhere? Thanks again for your support - much appreciated.

@amranidev
Copy link
Owner

amranidev commented Jan 6, 2018

  1. before migrating user table to the database make sure to add ORM migration adding $table->string('state');

  2. Pass an array of data to create.blade.php through the controller.

public create()
{
     $states = ["1" => "usa", "2" => "uk", "3" => "japan"];
     return view('example.create', compact("states"));
}
  1. Add the necessary html that we desperately need to your create blade.
<form . . . >
....        
     <div class="form-group">
        <label for="state">State</label>
        <select name="state" id="state">
            @foreach($states as $key => $value)
                <option value="{{$key}}">{{$value}}</option>
            @endforeach
        </select>
      </div>
...
</form>
  1. Store the piece of the data into the database through controller's store method
    public function store(Request $request)
    {
        $user = \App\User::findorfail(Auth::user()->id);
        $user->state = $request->state;
        return redirect('example');
    }

I hope this will answer your issue!!

@amranidev
Copy link
Owner

@hondaman900 Hi again!!

scaffold-interface uses the great laravel/spatie-permession package that makes you eligible to give permissions to your users to display some contents to them etc...

@Muhammadinaam
Copy link

Hi, this is a nice package but I think that the developers have stopped working on it. Maybe you can try this package: https://github.com/Muhammadinaam/speed-admin. It supports Laravel 8+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants