public function addHospital(Request $request) { $hosp = new Hospital(); $hosp->hospital_name = $request->get('hospital_name'); $hosp->city = $request->get('city'); $hosp->image = $request->get('image'); $hosp->hospital_level = $request->get('hospital_level'); $hosp->description = $request->get('description'); $success = $hosp->save(); return $success ? "true" : "false"; }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('hospitals')->delete(); $hospital = new Hospital(['name' => 'Provo Family', 'address' => '1528 Freedom Blvd 200 W']); $hospital->save(); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $data = $request->except('_token'); // var_dump($data); // exit(); $rules = ['name' => 'required', 'email' => 'email|unique:users,email|required', 'password' => 'required|confirmed', 'password_confirmation' => 'required', 'type' => 'required', 'city' => 'required']; $message = ['required' => 'The :attribute field is required.', 'unique' => 'Existing Mail.', 'confirmed' => 'Confirmed Password does not match.']; $validator = Validator::make($data, $rules, $message); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::route('hospitals.create')->withErrors($validator)->withInput(); } $data['password'] = bcrypt($data['password']); unset($data['password_confirmation']); $file = $data['filefield']; $extension = $file->getClientOriginalExtension(); $filename = $file->getFilename() . '.' . $extension; //Storage::disk('local')->put($file->getFilename().'.'.$extension, File::get($file)); $destination = 'images/'; $file->move($destination, $filename); $users = new User(); $users->name = $data["name"]; $users->email = $data['email']; $users->password = $data['password']; $users->role_id = 2; $users->mime = $file->getClientMimeType(); $users->photo = $file->getFilename() . '.' . $extension; $users->save(); //$g = User::whereRaw('id = (select max(`id`) from users)')->get(); $uid = DB::table('users')->where('id', DB::raw("(select max(`id`) from users)"))->get(); foreach ($uid as $did) { $userid = $did->id; } $hospitals = new Hospital(); $hospitals->hospital_name = $data["name"]; $hospitals->hospital_address = $data["address"]; $hospitals->hospital_ph = $data['phone']; $hospitals->hospital_email = $data['email']; $hospitals->hospital_website = $data['website']; $hospitals->hospital_type = $data['type']; $hospitals->city_id = $data['city']; $hospitals->about = $data['about']; $hospitals->direction = $data['direction']; $hospitals->location = $data['location']; $hospitals->mime = $file->getClientMimeType(); $hospitals->photo = $file->getFilename() . '.' . $extension; $hospitals->user_id = $userid; $hospitals->save(); $hid = DB::table('hospitals')->where('id', DB::raw("(select max(`id`) from hospitals)"))->get(); foreach ($hid as $hd) { $hospitalsid = $hd->id; } $facility = DB::select(DB::raw("select * from facilities")); foreach ($facility as $f) { if (isset($data[$f->id])) { $fac = new Facilityjunction(); $fac->hospital_id = $hospitalsid; $fac->facilities_id = $data[$f->id]; $fac->save(); } } $allhos = DB::select(DB::raw("select hospitals.*,cities.city_name from hospitals inner join cities on hospitals.city_id=cities.id ")); return View::make('hospitals.all')->with(compact('allhos')); }