本文整理汇总了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);
}
示例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;
}
示例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('Пользователь успешно создан'));
}
示例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}");
}
}
示例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']);
}
示例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));
}
示例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;
}
示例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());
}
}
示例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.');
}
}
示例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)]);
}
示例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)]);
}
}
示例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();
}
示例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);
}
示例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]);
}
示例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');
}