/** * Store a newly created resource in storage. * * @param App\Http\Requests\Admin\LocationRequest $request * @return \Illuminate\Http\Response */ public function store(LocationRequest $request) { $dataInsert = $request->except(['_token', 'width', 'height']); $dataInsert['size_display'] = $request->input('width') . ',' . $request->input('height'); Location::create(beforeSql($dataInsert)); return redirect()->action('Admin\\LocationController@index'); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); // seed Location foreach (range(0, 3) as $index) { $name = ['Banner', 'Privilege', 'ClickChannel', 'ShopOfTheWeek']; $width = [580, 640, 700]; $height = [420, 480, 540]; // $parentID = (Location::count() > 0)? Location::orderByRaw('RAND()')->first()->id : 0; $location = Location::create(['user_id' => User::orderByRaw('RAND()')->first()->id, 'location_name' => $name[$index], 'limit' => rand(1, 20), 'width' => $width[rand(0, count($width) - 1)], 'height' => $height[rand(0, count($height) - 1)], 'sort_order' => 1, 'flag_last' => $index ? 1 : 0, 'types' => $index + 1, 'status' => rand(0, 1)]); if ($index == 0) { foreach (range(1, 7) as $sub_index) { Location::create(['user_id' => User::orderByRaw('RAND()')->first()->id, 'location_name' => $name[$index] . ' sub' . $sub_index, 'limit' => 1, 'width' => $width[rand(0, count($width) - 1)], 'height' => $height[rand(0, count($height) - 1)], 'sort_order' => $sub_index, 'flag_last' => $sub_index == 7 ? 1 : 0, 'types' => $index + 1, 'status' => 1]); } } } // seed PageContent foreach (range(0, 60) as $index) { $location = Location::orderByRaw('RAND()')->first(); $sortOrder = $location->pageContents->count() > 0 ? $location->pageContents->count() + 1 : 1; $date = new DateTime(); $date_start = $date->format('Y-m-d'); $date->modify('+' . rand(1, 10) . ' day'); $date_end = $date->format('Y-m-d'); PageContent::create(['location_id' => $location->id, 'user_id' => User::orderByRaw('RAND()')->first()->id, 'name' => $faker->userName, 'link_url' => $faker->url, 'image_url' => $faker->imageUrl($width = $location->width, $height = $location->height), 'parent_id' => 0, 'sort_order' => $sortOrder, 'start' => $date_start, 'end' => $date_end, 'status' => rand(0, 1)]); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(int $id) { $setData['data'] = Location::where('id', $id)->get(); $cutData = explode(',', $setData['data'][0]['size_display']); $setData['data'][0]['width'] = $cutData[0]; $setData['data'][0]['height'] = $cutData[1]; // d($setData['data']->toArray()) ; $setData['actionLink'] = action('Admin\\LocationController@update', ['id' => $id]); if ($setData['data']) { $setData['action'] = 'edit'; return View::make('admin.location.add_edit', $setData); } else { return abort(404); } }
public static function getLocation() { return Location::where('types', 'ShopOfTheWeek')->where('types', self::$type); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(int $id) : int { return Location::where('id', $id)->first()->delete(); }