/** * Show the form for creating a new resource. * * @return Response */ public function create() { /*$rules = array( 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'location_id' => 'required', 'password' => 'required|same:password_confirmation' ); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $messages = $validator->messages(); return Response::json(array('error' => $messages, 'success' => '')); } else {*/ $data = Input::all(); //echo "<pre>"; print_r($data['first_name']);die; $receptionist = new Receptionist(); /*$receptionist->first_name = Input::get('first_name'); $receptionist->last_name = Input::get('last_name'); $receptionist->name = Input::get('first_name') . ' ' . Input::get('last_name'); $receptionist->email = Input::get('email'); $receptionist->location_id = Input::get('location_id'); $receptionist->password = bcrypt(Input::get('password')); $receptionist->password_org = Input::get('password');*/ $receptionist->first_name = $data['first_name']; $receptionist->last_name = $data['last_name']; $receptionist->name = $data['first_name'] . ' ' . $data['last_name']; $receptionist->email = $data['email']; $receptionist->location_id = $data['location_id']; $receptionist->password = $data['password']; $receptionist->password_org = $data['password']; $receptionist->status = 1; $receptionist->role_id = 3; if ($receptionist->save()) { $filename = $data['attachFile']; $extension = substr(strrchr($filename, '.'), 1); $imageName = $receptionist->id . '.' . $extension; $old_file = base_path() . '/public/uploads/avatar/' . $data['attachFile']; $new_file = base_path() . '/public/uploads/avatar/' . $imageName; $fileHand = fopen(base_path() . '/public/uploads/avatar/' . $data['attachFile'], 'r'); fclose($fileHand); rename($old_file, $new_file); $receptionist->avatar = $imageName; $receptionist->save(); return Response::json(array('success' => 'Receptionist has been added!')); /*$avatar_val = Input::file('avatar'); if(!empty($avatar_val)){ $extension = Input::file('avatar')->getClientOriginalExtension(); $imageName = $receptionist->id . '.' . $extension; $receptionist->avatar = $imageName; Input::file('avatar')->move(base_path() . '/public/uploads/avatar/', $imageName); } return Response::json(array('success' => 'Receptionist has been added!'));*/ } /*}*/ }
public function handleCreateReceptionist() { // create the validation rules ------------------------ $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email|unique:users', 'location' => 'required', 'password' => 'required|confirmed|min:6', 'avatar' => 'mimes:jpeg,bmp,png'); // do the validation ---------------------------------- // validate against the inputs from our form $validator = Validator::make(Input::all(), $rules); // check if the validator failed ----------------------- if ($validator->fails()) { // get the error messages from the validator $messages = $validator->messages(); // redirect our user back to the form with the errors from the validator return Redirect::action('CommonController@createReceptionist')->withErrors($validator)->withInput(); } else { $receptionist = new Receptionist(); $receptionist->first_name = Input::get('first_name'); $receptionist->last_name = Input::get('last_name'); $receptionist->name = Input::get('first_name') . ' ' . Input::get('last_name'); $receptionist->email = Input::get('email'); $receptionist->location_id = Input::get('location'); $receptionist->password = bcrypt(Input::get('password')); $receptionist->status = 1; $receptionist->role_id = 3; $receptionist->save(); if ($receptionist->save()) { $avatar_val = Input::file('avatar'); if (!empty($avatar_val)) { $extension = Input::file('avatar')->getClientOriginalExtension(); $imageName = $receptionist->id . '.' . $extension; $receptionist->avatar = $imageName; Input::file('avatar')->move(base_path() . '/public/uploads/avatar/', $imageName); } return Redirect::action('CommonController@receptionists'); } } }