public static function alias($str) { // переводим в транслит $str = Helper::rus2translit($str); // в нижний регистр $str = strtolower($str); // заменям все ненужное нам на "-" $str = preg_replace('~[^-a-z0-9_]+~u', '-', $str); // удаляем начальные и конечные '-' $str = trim($str, "-"); return $str; }
public function register() { if (\Request::all()) { $validator = \Validator::make(\Request::all(), ['email' => array('required', 'unique:users,email'), 'name' => 'required', 'password' => array('required', 'confirmed'), 'password_confirmation' => array('required'), 'term' => 'required']); if ($validator->fails()) { return \Redirect::route('admin_registration')->withErrors($validator)->withInput(); } else { $user = new User(); $user->email = \Request::get('email'); $user->name = \Request::get('name'); $user->password = \Hash::make(\Request::get('password')); $user->status = 1; $user->role = 0; $user->link = Helper::alias(\Request::get('name')); $user->save(); return \Redirect::route('administrator'); } } return view('abadmin::registration'); }
public function add() { if (\Request::all()) { $validator = \Validator::make(\Request::all(), ['email' => array('required', 'unique:users,email'), 'name' => 'required', 'password' => array('required', 'confirmed'), 'password_confirmation' => array('required'), 'role' => 'required', 'status' => 'required']); if ($validator->fails()) { return \Redirect::route('user/add')->withErrors($validator)->withInput(); } else { //dd(\Request::all()); $item = new User(); if (\Request::hasFile('logo')) { $dir = '/uploads/users' . date('/Y/' . $item->id . '/'); $filename = 'logo' . '.jpg'; //var_dump($dir); //die(); $image = \Request::file('logo'); $image->move(storage_path() . $dir, $filename); //$img = Image::make(storage_path().$dir.$filename); //$img->resize(140, 180); //$img->insert(public_path().'/template_image/watermark.png'); //$img->save(public_path().$dir.'thumb_'.$filename); $item->logo = $dir . 'thumb_' . $filename; //$item->save(); } $item->name = \Request::get('name'); $item->email = \Request::get('email'); $item->name = \Request::get('name'); $item->password = \Hash::make(\Request::get('password')); $item->phone = \Request::get('phone'); $item->description = \Request::get('description'); $item->status = \Request::get('status'); $item->role = \Request::get('role'); $item->link = Helper::alias(\Request::get('name')); $item->keywords = \Request::get('keywords'); $item->save(); return \Redirect::route('user/index'); } } return view('abadmin::user.add'); }