當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::create方法代碼示例

本文整理匯總了PHP中app\models\User::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::create方法的具體用法?PHP User::create怎麽用?PHP User::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\User的用法示例。


在下文中一共展示了User::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: register

 /**
  * The register method is responsible for checking/validating
  * the given input (email and password) and either return an error code or
  * create a new user.
  *
  * @return mixed
  */
 public function register()
 {
     $validateUser = $this->validateUser();
     if ($validateUser->status == 'error') {
         return \Response::json($validateUser);
     } else {
         //All's good, create a new user
         $user = User::create(['name' => \Request::get('name'), 'email' => \Request::get('email'), 'password' => bcrypt(\Request::get('password'))]);
         if (!\Request::has('role')) {
             $role['role'] = 'mobile';
         } else {
             $role['role'] = 'web';
         }
         //assign role to user
         $role = Role::where('name', $role)->first();
         $user->roles()->save($role);
         $device = $this->sanitizeDevice($user->id);
         $this->deviceService->store($user->id, $device);
         //Retrieve the JWT and send back to the Controller
         $token = \JWTAuth::fromUser($user);
         $response = new ApiResponse();
         $response->status = 'success';
         $response->message = ['token' => $token];
     }
     return \Response::json($response);
 }
開發者ID:scify,項目名稱:city-r-us-service,代碼行數:33,代碼來源:UserService.php

示例2: createWithRandomPassword

 public function createWithRandomPassword($attributes = [])
 {
     $attributes['password'] = Hash::make(str_random());
     $user = $this->user->create($attributes);
     $this->emailPasswordReset($user->email, function ($message) {
         $message->newUser = true;
     });
     return $user;
 }
開發者ID:rtablada,項目名稱:student-grading,代碼行數:9,代碼來源:DbUserGateway.php

示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $this->validate($request, ['email' => 'required|email|unique:users', 'password' => 'required|min:6', 'password_confirm' => 'required|same:password'], ['email.required' => 'Поле email не заполнено', 'email.email' => 'Введите верный email', 'email.unique' => 'Такой email уже существует!', 'password.required' => 'Задайте пароль', 'password.min' => 'Пароль должен быть длиной не менее 6 символов', 'password_confirm.required' => 'Введите подтверждение пароля', 'password_confirm.same' => 'Подтверждение пароля введено не верно']);
     $input = $request->all();
     $user = $this->users->create($input);
     $user->password = bcrypt($input['password']);
     $user->save();
     return redirect()->route('admin.user.index')->with('messages', array('Пользователь успешно создан'));
 }
開發者ID:qubikr,項目名稱:laravel,代碼行數:15,代碼來源:UserController.php

示例4: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $email = $this->ask('What is the email for the new super user: ');
     $password = $this->secret('What is the new super user\'s password: ');
     $attrs = ['email' => $email, 'password' => Hash::make($password)];
     if ($this->confirm("Are you sure you want to create a new user for {$email}? [yes|no]", false)) {
         $user = $this->user->create($attrs);
         $user->ensureRole('admin');
         $this->info("User created for email {$email} with id {$user->id}");
     }
 }
開發者ID:rtablada,項目名稱:student-grading,代碼行數:16,代碼來源:CreateAdminUser.php

示例5: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = Role::select('id')->where('name', '=', 'admin')->first();
     $user = User::create(['name' => 'Administrador', 'lastname' => 'Administrador', 'email' => 'admin@admin.com', 'password' => bcrypt('admin'), 'dni' => '34785999', 'state_id' => '12', 'city_id' => '228', 'role_id' => $role->id, 'active' => '1']);
     $role = Role::select('id')->where('name', '=', 'user')->first();
     $user = User::create(['name' => 'User', 'lastname' => 'User', 'email' => 'user@user.com', 'password' => bcrypt('123456'), 'dni' => '34785998', 'state_id' => '12', 'city_id' => '228', 'role_id' => $role->id, 'active' => '1']);
 }
開發者ID:mauhftw,項目名稱:mizustats,代碼行數:12,代碼來源:UsersSeeder.php

示例6: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // ADMIN USER (DIMIZAS)
     User::create(array('name' => 'Christos', 'lastname' => 'Dimizas', 'email' => 'x_dimizas@hotmail.com', 'password' => Hash::make('1234qwer'), 'user_role_id' => 1, 'user_subrole_id' => null, 'activation_status' => 1, 'is_deactivated' => 0));
     // ADMIN USER (IASONIDIS)
     User::create(array('name' => 'Theodoros', 'lastname' => 'Iasonidis', 'email' => 'tiasonidis.scify@gmail.com', 'password' => Hash::make('!1234qwer!'), 'user_role_id' => 1, 'user_subrole_id' => null, 'activation_status' => 1, 'is_deactivated' => 0));
 }
開發者ID:scify,項目名稱:Benefile,代碼行數:12,代碼來源:UsersTableSeeder.php

示例7: create

 public function create($requestData)
 {
     $settings = Settings::first();
     $password = bcrypt($requestData->password);
     $role = $requestData->roles;
     $department = $requestData->departments;
     $companyname = $settings->company;
     if ($requestData->hasFile('image_path')) {
         if (!is_dir(public_path() . '/images/' . $companyname)) {
             mkdir(public_path() . '/images/' . $companyname, 0777, true);
         }
         $settings = Settings::findOrFail(1);
         $file = $requestData->file('image_path');
         $destinationPath = public_path() . '/images/' . $companyname;
         $filename = str_random(8) . '_' . $file->getClientOriginalName();
         $file->move($destinationPath, $filename);
         $input = array_replace($requestData->all(), ['image_path' => "{$filename}", 'password' => "{$password}"]);
     } else {
         $input = array_replace($requestData->all(), ['password' => "{$password}"]);
     }
     $user = User::create($input);
     $user->roles()->attach($role);
     $user->department()->attach($department);
     $user->save();
     Session::flash('flash_message', 'User successfully added!');
     //Snippet in Master.blade.php
     return $user;
 }
開發者ID:Bottelet,項目名稱:Flarepoint-crm,代碼行數:28,代碼來源:UserRepository.php

示例8: postForm

 public function postForm(FormAdminRequest $request)
 {
     try {
         $dataAdmin = $request->all();
         $password = $request->get('password', null);
         if (isset($dataAdmin['id']) && $dataAdmin['id'] != '') {
             $data = $request->except(array('password'));
             $runtime = User::find($dataAdmin['id']);
             $runtime->fill($data);
             $runtime->password = $runtime->password;
             if (!empty($password)) {
                 $runtime->password = Hash::make($password);
             }
             $runtime->save();
             $msg = 'Usuario Editado!';
         } else {
             $role = Role::whereName(User::ROL_CONTENIDO_ADMIN)->first();
             $dataAdmin['password'] = Hash::make($password);
             $NewUser = User::create($dataAdmin);
             $msg = 'Usuario Guardado!';
             RoleUser::create(['user_id' => $NewUser->id, 'role_id' => $role->id]);
         }
         return redirect(action('Admin\\AdminController@getIndex'))->with('messageSuccess', $msg);
     } catch (Exception $exc) {
         dd($exc->getMessage());
     }
 }
開發者ID:josmel,項目名稱:buen,代碼行數:27,代碼來源:AdminController.php

示例9: run

 /**
  * Run the database seeds.
  */
 public function run()
 {
     User::create($this->getUserDetails() + ['is_admin' => true]);
     if (!app()->runningUnitTests()) {
         $this->command->info('Admin user created. You can (and should) remove the auth details from .env now.');
     }
 }
開發者ID:namdau,項目名稱:koel,代碼行數:10,代碼來源:UserTableSeeder.php

示例10: run

 public function run()
 {
     $this->command->info('Running UserTableSeeder');
     Eloquent::unguard();
     $account = Account::create(['name' => 'Test Account', 'account_key' => str_random(16), 'timezone_id' => 1]);
     User::create(['email' => TEST_USERNAME, 'username' => TEST_USERNAME, 'account_id' => $account->id, 'password' => Hash::make(TEST_PASSWORD)]);
 }
開發者ID:jgyaipl,項目名稱:invoice-ninja,代碼行數:7,代碼來源:UserTableSeeder.php

示例11: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 30) as $index) {
         User::create(['first_name' => $faker->firstName(), 'last_name' => $faker->lastName(), 'email' => $faker->email(), 'password' => bcrypt('secret'), 'hourly_rate' => $faker->numberBetween(25, 250)]);
     }
 }
開發者ID:skygravity,項目名稱:laravel-closure-table,代碼行數:12,代碼來源:UsersTableSeeder.php

示例12: postUser

 /**
  * Create new account
  *
  * @param Request $request
  * @return Response
  */
 public function postUser(Request $request)
 {
     if (!$this->appKeyAvailable($request)) {
         return $this->notAuthorized($request);
     }
     $validator = Validator::make($request->all(), ['username' => 'required|unique:users,username|min:4|max:32', 'email' => 'required|unique:users,email|max:32|email', 'password' => 'required|min:6']);
     if ($validator->fails()) {
         $this->setResultError($validator->messages(), 400);
     } else {
         $user = $request->all();
         $user['password'] = Hash::make($user['password']);
         $this->user = User::create($user);
         if (isset($user['profile'])) {
             if (is_array($user['profile'])) {
                 foreach ($user['profile'] as $key => $value) {
                     Profile::create(['key' => $key, 'value' => $value, 'user_id' => $this->user->id]);
                 }
             }
         }
         $this->setResultOk();
         $this->setSessionHash();
         $this->setUserData();
     }
     return $this->setResponse();
 }
開發者ID:Baasify,項目名稱:Baasify,代碼行數:31,代碼來源:UsersController.php

示例13: run

 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     DB::table('permission_role')->truncate();
     DB::table('role_user')->truncate();
     DB::table('users')->truncate();
     DB::table('roles')->truncate();
     DB::table('permissions')->truncate();
     DB::table('permission_groups')->truncate();
     DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     $faker = Faker\Factory::create();
     //User
     $admin = User::create(['email' => 'admin@admin.com', 'name' => '管理員', 'password' => bcrypt('adminadmin')]);
     $test_user = User::create(['email' => 'test@test.com', 'name' => '測試用戶', 'password' => bcrypt('testtest')]);
     //Roles
     $role_admin = Role::create(['name' => 'admin', 'display_name' => '管理員']);
     $role_editor = Role::create(['name' => 'editor', 'display_name' => '編輯']);
     $role_user = Role::create(['name' => 'user', 'display_name' => '普通用戶']);
     //Permission&PermissionGroup
     PermissionGroup::create(['name' => '後台']);
     PermissionGroup::create(['name' => 'RBAC', 'parent_id' => 1]);
     Permission::create(['name' => 'dashboard_view', 'display_name' => '首頁', 'group_id' => 1]);
     $models = [['route_name' => 'users', 'menu_name' => '帳戶', 'group_id' => 3, 'group_pid' => 2], ['route_name' => 'roles', 'menu_name' => '角色', 'group_id' => 4, 'group_pid' => 2], ['route_name' => 'permissions', 'menu_name' => '權限', 'group_id' => 5, 'group_pid' => 2], ['route_name' => 'permissiongroups', 'menu_name' => '權限分組', 'group_id' => 6, 'group_pid' => 2], ['route_name' => 'articles', 'menu_name' => '文章', 'group_id' => 7, 'group_pid' => 1], ['route_name' => 'settings', 'menu_name' => '配置', 'group_id' => 8, 'group_pid' => 1]];
     foreach ($models as $key => $model) {
         PermissionGroup::create(['name' => $model['menu_name'], 'parent_id' => $model['group_pid']]);
         Permission::create(['group_id' => $model['group_id'], 'name' => $model['route_name'] . '_view', 'display_name' => $model['menu_name'] . '菜單']);
         Permission::create(['group_id' => $model['group_id'], 'name' => $model['route_name'] . '_create', 'display_name' => '新建' . $model['menu_name']]);
         Permission::create(['group_id' => $model['group_id'], 'name' => $model['route_name'] . '_update', 'display_name' => '修改' . $model['menu_name']]);
         Permission::create(['group_id' => $model['group_id'], 'name' => $model['route_name'] . '_delete', 'display_name' => '刪除' . $model['menu_name']]);
     }
     //Roles Users
     $test_user->roles()->save($role_editor);
     //Roles Users
     // $role_admin->givePermissionTo($permission_admin_user);
 }
開發者ID:hramose,項目名稱:laravel-5-admin,代碼行數:35,代碼來源:UsersTableSeeder.php

示例14: create

 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     if ($data['user_role_id'] != 2) {
         return User::create(['name' => $data['name'], 'lastname' => $data['lastname'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'user_role_id' => $data['user_role_id'], 'activation_status' => 0, 'is_deactivated' => 0]);
     }
     return User::create(['name' => $data['name'], 'lastname' => $data['lastname'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'user_role_id' => $data['user_role_id'], 'user_subrole_id' => $data['user_subrole_id'], 'activation_status' => 0, 'is_deactivated' => 0]);
 }
開發者ID:scify,項目名稱:Benefile,代碼行數:13,代碼來源:AuthController.php

示例15: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed|min:6']);
     $data = $request->input();
     User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     return redirect('/users')->withMessage('<i class="glyphicon glyphicon-ok"></i> This user has been created');
 }
開發者ID:hannahtinkler,項目名稱:too-tool-for-school,代碼行數:13,代碼來源:UsersController.php


注:本文中的app\models\User::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。