public function fire(array $data) { $this->validator->setScenario('register')->validate($data); $data['password'] = $this->hasher->make($data['password']); $user = $this->userModel->create($data); event(new UserRegistered($user)); return $user; }
/** * Register user * * @param \Illuminate\Http\Request $request * @param \Tajrish\Services\UserTokenHandler $tokenService * @return \Illuminate\Http\JsonResponse */ public function postRegister(Request $request, UserTokenHandler $tokenService) { $this->validate($request, ['email' => 'required|email|max:255|unique:users,email', 'password' => 'required|string|max:255', 'name' => 'required|string']); $user = User::create(['email' => $request->input('email'), 'password' => bcrypt($request->input('password')), 'name' => $request->input('name')]); $token = $tokenService->createAndGetTokenForUser($user); return response()->json(['created' => true, 'token_entity' => $token, 'user' => $user]); }
protected function createUsers() { \Tajrish\Models\User::truncate(); /** @var \Tajrish\Repositories\UserTokenRepository $repo */ $repo = app(\Tajrish\Repositories\UserTokenRepository::class); $user = \Tajrish\Models\User::create(['name' => 'رضا شادمان', 'email' => '*****@*****.**', 'password' => $pass = bcrypt('1234567'), 'province_id' => \Tajrish\Models\Province::where('name', 'تهران')->firstOrFail()->id]); $repo->makeUniqueTokenForUser($user, \Tajrish\Services\Tosan\Helpers\TokenGenerator::generate()); $mockUsers = [['name' => 'تبسم لطیفی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'سامان ولی زاده', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'سیاوش آقائی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'علی یوسفی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'حسین شعبانی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'حامد دلفان', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'رضا کیانی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'حامد بهداد', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'بهرام رادانس', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'رضا فروتن', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'هدیه تهرانی', 'email' => '*****@*****.**', 'password' => $pass]]; foreach ($mockUsers as $user) { \Tajrish\Models\User::create(array_merge($user, ['province_id' => rand(1, 6)])); $repo->makeUniqueTokenForUser($user, \Tajrish\Services\Tosan\Helpers\TokenGenerator::generate()); } }