function addEvent(Request $request) { $current_user = Session::get('user'); if (!isset($current_user)) { return 'you must login first.'; } else { $id_tmp = 0; if (($count = Item::count()) != 0) { $id_tmp = Item::skip($count - 1)->first()->item_id; } $id_tmp = $id_tmp + 1; $item = new Item(); $event = new Event(); $location = new Location(); $photo = new PhotoGallery(); /*---------------------upload_picture-----------------------*/ $file = Input::file('profile_picture'); if ($file != null) { $destinationPath = 'img/'; $filename = md5(microtime() . $file->getClientOriginalName()) . "." . $file->getClientOriginalExtension(); Input::file('profile_picture')->move($destinationPath, $filename); $num_photo = DB::table('photo_gallery')->count(); $photo->photo_id = DB::table('photo_gallery')->skip($num_photo - 1)->first()->photo_id + 1; $photo->link_item_id = $id_tmp; $photo->photo_url = '/' . $destinationPath . $filename; $item->title_picture = $photo->photo_url; $photo->save(); } /*---------------------------------------------------------*/ $item->item_id = $id_tmp; $item->title = $request->in_new_title; $item->description = $request->in_new_description; $item->tel = $request->in_new_tel; $item->user_id = $current_user[5]; $event->start_date = $request->in_new_start_date; $event->end_date = $request->in_new_end_date; $event->entrance_fee = $request->in_new_entrance_fee; $event->type = $request->in_new_type; $event->parking = $request->in_new_parking; $event->website_url = $request->in_new_website_url; $event->link_item_id = $id_tmp; $location->hint = $request->in_new_hint; $location->build = $request->in_new_build; $location->street_address = $request->in_new_street_address; $location->sub_district = $request->in_new_sub_dis; $location->district = $request->in_new_district; $location->province = $request->in_new_province; $location->postal_code = $request->in_new_post_code; $location->lat = $request->in_new_lat; $location->long = $request->in_new_lng; $location->link_item_id = $id_tmp; $item->save(); $location->save(); $event->save(); return redirect('/page_event/info/' . $id_tmp); } }