public function post(Request $request) { $id = $request->input('id'); $validate = Validator::make($request->all(), Equipment::$validation_rules); if ($validate->passes()) { $equipment_id = $request->input('equipment_id'); $name = $request->input('name'); $rate = $request->input('rate'); if ($id != "") { $equipment = Equipment::find($id); } else { $equipment = new Equipment(); } $equipment->equipment_id = $equipment_id; $equipment->name = $name; $equipment->rate = $rate; if ($equipment->save()) { if ($id != "") { return redirect()->action('EquipmentController@add', $id)->with('success', 'Equipment has been successfully saved'); } else { return $this->redirect_to_equipment_add->with('success', 'Equipment has been successfully saved'); } } else { return $this->redirect_to_equipment_add->with('error', 'Equipment save error'); } } else { if ($id != "") { return redirect()->action('EquipmentController@add', $id)->with('success', 'Equipment has been successfully saved'); } else { return $this->redirect_to_equipment_add->withErrors($validate)->withInput(); } } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $equipment = new Equipment(); $equipment->name_jp = Input::get('name_jp'); $equipment->name_en = Input::get('name_en'); $equipment->name_cn = Input::get('name_cn'); $equipment->desc_jp = Input::get('desc_jp'); $equipment->desc_en = Input::get('desc_en'); $equipment->desc_cn = Input::get('desc_cn'); $equipment->type = Input::get('type'); $equipment->sub_type = Input::get('sub_type'); $equipment->icon = Input::get('icon'); $equipment->image = Input::get('image'); $equipment->rare = Input::get('rare'); $equipment->race = Input::get('race'); $equipment->attr = Input::get('attr'); $equipment->job = Input::get('job'); $equipment->status_1_type = Input::get('status_1_type'); $equipment->status_1_value = Input::get('status_1_value'); $equipment->status_1_add = Input::get('status_1_add'); $equipment->status_2_type = Input::get('status_2_type'); $equipment->status_2_value = Input::get('status_2_value'); $equipment->status_2_add = Input::get('status_2_add'); $equipment->status_3_type = Input::get('status_3_type'); $equipment->status_3_value = Input::get('status_3_value'); $equipment->status_3_add = Input::get('status_3_add'); if ($equipment->save()) { return Redirect::to('admin/equipment'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('equipment')->delete(); $equipment = new Equipment(['name' => 'MRI']); $equipment->save(); $equipment = new Equipment(['name' => 'CAT']); $equipment->save(); $equipment = new Equipment(['name' => 'X-Ray']); $equipment->save(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Equipment $equipment) { $validator = Validator::make(Input::all(), Equipment::$rules); if ($validator->passes()) { $equipment = new Equipment(); $equipment->category_id = Input::get('category_id'); $equipment->title = Input::get('title'); $equipment->description = Input::get('description'); $equipment->price = Input::get('price'); $image = Input::file('image'); $filename = time() . "-" . $image->getClientOriginalName(); Image::make($image->getRealPath())->resize(468, 249)->save(pub - lic_path() . '/img/equipment/' . $filename); $equipment->image = 'img/equipment/' . $filename; $equipment->save(); return Redirect::to('/admin.equipment.index')->with('message', 'Equipment Created'); } }
public function run() { # Clear the tables to a blank slate # Disable FK constraints so that all rows can be deleted, even if there's an attachd FK DB::statement('SET FOREIGN_KEY_CHECKS=0'); DB::statement('TRUNCATE equipment'); DB::statement('TRUNCATE category_equipment'); $audiorecorder = new Equipment(); $audiorecorder->name = 'audiorecorder'; $audiorecorder->brand = 'Sony'; $audiorecorder->model = 'L-185'; $audiorecorder->serial_number = '123456'; $audiorecorder->price = 1500; $audiorecorder->availability = 1; $audiorecorder->image_path = 'images/marantz_1.jpg'; $audiorecorder->save(); $dongle = new Equipment(); $dongle->name = 'dongle'; $dongle->brand = 'Apple'; $dongle->model = 'l-185'; $dongle->price = 1500; $dongle->availability = 1; $dongle->image_path = 'images/mac_dungle.jpg'; $dongle->save(); # equipment $laptop = new Equipment(); $laptop->name = 'laptop'; $laptop->brand = 'Dell'; $laptop->model = 'Latitude'; $laptop->serial_number = '123456'; $laptop->price = 1500; $laptop->availability = 1; $laptop->image_path = 'images/dell_laptop.jpg'; $laptop->save(); $mac = new Equipment(); $mac->name = 'mac'; $mac->brand = 'Apple'; $mac->model = 'Mac-Pro'; $mac->serial_number = '123789'; $mac->price = 1500; $mac->availability = 1; $mac->image_path = 'images/mac-pro.jpg'; $mac->save(); $microphone = new Equipment(); $microphone->name = 'microphone'; $microphone->brand = 'Shure'; $microphone->model = 'sm-58'; $microphone->serial_number = '1255456'; $microphone->price = 1500; $microphone->availability = 1; $microphone->image_path = 'images/shure_mic.jpg'; $microphone->save(); $projector = new Equipment(); $projector->name = 'projector'; $projector->brand = 'Sanyo'; $projector->model = 'wtc-500'; $projector->serial_number = '1254566'; $projector->price = 1500; $projector->availability = 1; $projector->image_path = 'images/sanyo_projector.jpg'; $projector->save(); $tripod = new Equipment(); $tripod->name = 'tripod'; $tripod->brand = 'Manfrotto'; $tripod->model = 'T-25'; $tripod->serial_number = '1254566'; $tripod->price = 1500; $tripod->availability = 1; $tripod->image_path = 'images/tripod.jpg'; $tripod->save(); $videocamera = new Equipment(); $videocamera->name = 'videocamera'; $videocamera->brand = 'Sony'; $videocamera->model = 'ts4000'; $videocamera->serial_number = '1254566'; $videocamera->price = 1500; $videocamera->availability = 1; $videocamera->image_path = 'images/hdzoom_cam.jpg'; $videocamera->save(); $sound_system = new equipment(); $sound_system->name = 'sound_system'; $sound_system->brand = 'Yamaha'; $sound_system->model = 't-25'; $sound_system->serial_number = '1254566'; $sound_system->price = 1500; $sound_system->availability = 1; $sound_system->image_path = 'images/sound_system.jpg'; $sound_system->save(); $audiorecorder = App\Equipment::where('name', 'audiorecorder')->get()->first(); $category = App\Category::where('name', '=', 'audiorecorder')->first(); $audiorecorder->categories()->attach($category->id); $category = App\Category::where('name', '=', 'dongle')->first(); $dongle = App\Equipment::where('name', 'dongle')->get()->first(); $dongle->categories()->attach($category->id); $category = App\Category::where('name', '=', 'laptop')->first(); $laptop = App\Equipment::where('name', 'laptop')->get()->first(); $laptop->categories()->attach($category->id); $category = App\Category::where('name', '=', 'mac')->first(); $mac = App\Equipment::where('name', 'audiorecorder')->get()->first(); $mac->categories()->attach($category->id); $category = App\Category::where('name', '=', 'microphone')->first(); $microphone = App\Equipment::where('name', 'mac')->get()->first(); $microphone->categories()->attach($category->id); $category = App\Category::where('name', '=', 'projector')->first(); $projector = App\Equipment::where('name', 'projector')->get()->first(); $projector->categories()->attach($category->id); $category = App\Category::where('name', '=', 'tripod')->first(); $tripod = App\Equipment::where('name', 'tripod')->get()->first(); $tripod->categories()->attach($category->id); $category = App\Category::where('name', '=', 'videocamera')->first(); $videocamera = App\Equipment::where('name', 'videocamera')->get()->first(); $videocamera->categories()->attach($category->id); $category = App\Category::where('name', '=', 'sound_system')->first(); $sound_system = App\Equipment::where('name', 'sound_system')->get()->first(); $sound_system->categories()->attach($category->id); }