/** * 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)]); } }
/** * 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']); $dataInsert['user_id'] = $request->session()->get('backoffice')['id']; Location::create(beforeSql($dataInsert)); Cache::forget('cacheMenuLeft'); return redirect()->action('Admin\\LocationController@index'); }