public function run() { $faker = Faker\Factory::create(); DB::table('shop_profiles')->delete(); foreach (range(1, 10) as $index) { \ZaWeb\Shops\Models\ShopProfile::create(['name' => $faker->name, 'phone' => $faker->phoneNumber, 'email' => $faker->email, 'description' => $faker->paragraph(4)]); } }
/** * @param ShopRequest $request * @return \Illuminate\Http\RedirectResponse */ public function storeShop(ShopRequest $request) { $attachment = ImageUploadFacade::attachmentUpload($request->file('attachment'), new Attachment(), 'shops'); $shop = new Shops(); $shop->capacity = $request->get('capacity'); $shop->city_id = $request->get('city'); $shop->paid_at = Carbon::now()->addMonth(); $shopProfile = new ShopProfile(); $shopProfile->fill($request->except('attachment')); $shopProfile->save(); $shop->profile()->associate($shopProfile); if ($attachment) { $shop->attachment()->associate($attachment); } $page = $request->page; $shop->user_id = $request->user_id; $shop->save(); return redirect($page); }
public function run() { $faker = Faker\Factory::create(); DB::table('shops')->delete(); foreach (range(1, 3) as $index) { $city_id = \App\Models\Cities::orderBy(DB::raw('RAND()'))->first()->id; $user_id = rand(1, 3); $profile_id = \ZaWeb\Shops\Models\ShopProfile::orderBy(DB::raw('RAND()'))->first()->id; $attachment_id = \App\Models\Attachment::orderBy(DB::raw('RAND()'))->first()->id; \ZaWeb\Shops\Models\Shops::create(['user_id' => $user_id, 'city_id' => $city_id, 'capacity' => 300, 'attachment_id' => $attachment_id, 'profile_id' => $profile_id, 'created_at' => date('Y-m-d G:i:s'), 'updated_at' => date('Y-m-d G:i:s')]); } }
/** * Update the specified resource in storage. * * @param ShopRequest $request * @param Shops $shops * @return Response * @internal param int $id */ public function update(ShopRequest $request, Shops $shops) { if (Auth::check()) { if ($shops->user_id != Auth::user()->id) { return redirect('/'); } } ShopProfile::find($shops->profile_id)->update($request->except('attachment')['profile']); if ($request->file('attachment')) { $attachment = ImageUploadFacade::attachmentUpload($request->file('attachment'), new Attachment(), 'shops'); $shops->fill($request->only('attachment')); $shops->attachment()->associate($attachment); } $shops->city_id = $request->get('city'); $shops->update(); return redirect()->route('shops.show', $shops->id); }