0

I am developing web app using laravel. when a client/office create an account in my app they have the provision for adding their staffs. when they add a staff app should create a account for them under the client/office account and should assign a temporary username and password for them to log in to the app.

My Problems:

  • How can i implement automatic registration of users
  • how to assign temporary username and password for them I am using laravel 5.6 with homestead and php

Any help and suggestion are appreciated

thanks rufaidulk

4
  • 1
    did you mean php artisan make:auth ? Commented Aug 27, 2018 at 18:37
  • When you setup the relationships in Laravel, you can do something like $client->staff->create(['username' => 'temp', 'password' => 'temp']); Look at the docs: laravel.com/docs/5.6/eloquent-relationships (p.s. I think you need a many to many relationship, because clients can have many staff and staff can belong to many clients. If that last part is not true, it should be a one to many relationship. Commented Aug 27, 2018 at 18:45
  • Also please show us the code you already wrote. Commented Aug 27, 2018 at 18:45
  • i am just used default authentication in laravel Commented Aug 27, 2018 at 19:14

2 Answers 2

1

You can create users like you do for other models:

User::create([
  ...
  "email"=>$request->email, 
  "password"=>Hash::make($request->password)
  ...
]);

Try adding some validation first, and check that the user creating the account has all required permissions.

Sign up to request clarification or add additional context in comments.

Comments

1

You could run php artisan make:auth in the console, this will create the routes, controllers and migrations for the user auth process

then in the register controller that was generated you could create the user and authenticate them with

protected function create(array $data)
    {

        return User::create([
            'email'      => $data['email'],
            'password'   => Hash::make($data['password']),
            ...
        ]);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.