[Vuejs]-Creating a multiselect with a many-to-many relationship using roles as a foreign key

-1👍

First thing I want to review your code why we used inertia js is used to avoid writing calls from vue or other frontend frameworks and you can directory pass data from the controller.Here your modified code

 public function create()
{
    $roles = Role::all();
    return inertia('Users/Create',compact('roles'));
}

public function store(StoreUserRequest $request)
{
    $validatedData = $request->all();

    $validatedData['password'] = Hash::make($validatedData['password']);

   User::create($validatedData);

   return Redirect::route('users.index')
            ->with('message', 'User created successfully');
}

And you can received as props inside vue that props name that you give roles like that

Leave a comment