public function run() { $faker = Faker\Factory::create(); DB::table('ad_types')->delete(); AdType::create(['name' => 'Продам', 'description' => $faker->sentence(8)]); AdType::create(['name' => 'Куплю', 'description' => $faker->sentence(8)]); AdType::create(['name' => 'Отдам', 'description' => $faker->sentence(8)]); }
public function run() { $faker = Faker\Factory::create(); DB::table('advertisement')->delete(); foreach (range(1, 30) as $index) { $category_id = Category::orderBy(DB::raw('RAND()'))->first()->id; $city_id = Cities::orderBy(DB::raw('RAND()'))->first()->id; $type_id = AdType::orderBy(DB::raw('RAND()'))->first()->id; // $a_hash = AdsAttachment::orderBy(DB::raw('RAND()'))->first()->hash; Advertisement::create(['category_id' => $category_id, 'text' => $faker->paragraph(4), 'user_id' => 1, 'city_id' => $city_id, 'type_id' => $type_id, 'price' => 12345, 'approved' => rand(0, 1)]); } }
public function __construct() { $this->categories = Category::lists('title', 'id'); $this->cities = Cities::get()->toArray(); $this->ad_types = AdType::lists('name', 'id'); }
public function compose($view) { $types = AdType::all(); $view->with('types', $types); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(AdType $type) { $type->delete(); return redirect()->route('admin.type.index'); }
/** * @param Advertisement $advertisement * @param Request $request * @return mixed */ public function index(Advertisement $advertisement, Request $request) { $ads = $advertisement::orderBy('top', 'desc')->orderBy('id', 'desc'); $input = \Input::all(); if ($request->input('search')) { $ads = $advertisement->where('text', 'LIKE', '%' . $request->input('search') . '%')->orderBy('top', 'desc')->orderBy('id', 'desc'); } if ($request->input('category_id')) { if ($input['category_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $ads = Advertisement::with('category')->where('category_id', '=', $category->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id')) { if ($input['city_id'] != 'null') { $city = Cities::findOrFail(\Input::get('city_id')); $ads = Advertisement::with('city')->where('city_id', '=', $city->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('type_id')) { if ($input['type_id'] != 'null') { $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('type')->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('category_id') && $request->input('type_id')) { if ($input['category_id'] != 'null' && $input['type_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('category')->with('type')->where('category_id', '=', $category->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id') && $request->input('category_id')) { if ($input['category_id'] != 'null' && $input['city_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $city = Cities::findOrFail(\Input::get('city_id')); $ads = Advertisement::with('city')->with('category')->where('city_id', '=', $city->id)->where('category_id', '=', $category->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id') && $request->input('type_id')) { if ($input['city_id'] != 'null' && $input['type_id'] != 'null') { $city = Cities::findOrFail(\Input::get('city_id')); $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('city')->with('type')->where('city_id', '=', $city->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id') && $request->input('category_id') && $request->input('type_id')) { if ($input['category_id'] != 'null' && $input['city_id'] != 'null' && $input['type_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $city = Cities::findOrFail(\Input::get('city_id')); $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('city')->with('category')->with('type')->where('city_id', '=', $city->id)->where('category_id', '=', $category->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($_SERVER['HTTP_HOST'] == env('HOST')) { $ads = $ads->paginate(10); } else { $ads = $ads->paginate(20); } return View::make('welcome', compact('ads'))->with('input', \Input::all()); }