/** * Create and get token for user * * @param \Tajrish\Models\User $user * @return UserToken */ public function createAndGetTokenForUser(User $user) { $tokenIsNotAvailable = true; while ($tokenIsNotAvailable) { $generatedToken = TokenGenerator::generate(); $tokenIsNotAvailable = $this->repo->tokenExists($user, $generatedToken); } $tokenEntity = $this->repo->makeUniqueTokenForUser($user, $generatedToken); $tokenEntity->setHidden(['id', 'user_id', 'created_at', 'updated_at']); return $tokenEntity; }
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()); } }