vendredi 19 juin 2020

Laravel Assign User to Shop in Create Form

I've form to add new users and assign user to Shop

Also, I've user_id field in Shop Table

What am i trying to do is:

in create form there will be a select box with all Shops name that doesn't have user id

so i want to assign user to selected Shop from the select box

Any Ideas?

Store Function

public function store(Request $request)
{
    $this->validate($request, array(
        'name'         => 'required|string|max:255',
        'email'          => 'required|string|email|max:255|unique:users',
        'password'          => 'required|string|min:8',
    ));
    $password = Hash::make($request->password);
    $user = new User;
    $user->name = $request->input('name');
    $user->email = $request->input('email');
    $user->password = $password;
    $user->save();

    return redirect('admin/users')->with('success', 'user is successfully saved');
}

View

<form action="" method="post">
                                    @csrf
                                    @method('post')
                                <div class="form-group">
                                    <label for="wizard-validation-classic-firstname">Name</label>
                                    <input class="form-control" type="text" id="wizard-validation-classic-firstname" name="name">
                                </div>
                                <div class="form-group">
                                    <label for="wizard-validation-classic-lastname">E-mail</label>
                                    <input class="form-control" type="text" id="wizard-validation-classic-lastname" name="email">
                                </div>
                                <div class="form-group">
                                    <label for="wizard-validation-classic-lastname">password</label>

                                            <input type="text" class="form-control input-lg" name="password">

                                </div>

                                </form>


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3fDpPBd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire