public function __construct() { $this->middleware('auth'); if (Auth::user()) { $this->favs = Fav::getAll(); $this->categories = Category::getAll(); } }
public function questions() { if (Auth::check()) { $comments = Comment::whereHas('ad', function ($query) { $query->where(['author_id' => Auth::user()->id, 'answer_to' => null]); })->orWhereHas('answerTo', function ($query) { $query->where('author_id', Auth::user()->id); })->orderBy('created_at', 'desc')->get(); return view('profile.questions', ['categories' => Category::getAll(), 'comments' => $comments]); } else { return redirect('/'); } }
/** * Bootstrap the application services. * * @return void */ public function boot() { view()->composer(['layout', 'errors.layout', 'sub.filters'], function ($view) { $new_questions = 0; if (Auth::check()) { $new_questions = Comment::where('is_viewed', false)->whereHas('ad', function ($query) { $query->where(['author_id' => Auth::user()->id, 'answer_to' => null]); })->orWhereHas('answerTo', function ($query) { $query->where(['author_id' => Auth::user()->id]); })->where('is_viewed', false)->count(); } $view->with(['new_questions' => $new_questions, 'categories' => Category::getAll()]); }); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(StoreAdRequest $request, $id) { $ad = Ad::findOrFail($id); if (Gate::allows('update', $ad)) { $isFree = $request['is_free'] == 'on'; $ad->update(['title' => $request['title'], 'text' => $request['text'], 'author_name' => $request['name'], 'phone' => $request['phone'], 'category_id' => $request['category_id'], 'city_id' => $request['city_id'], 'price' => $isFree ? 0 : $request['price'], 'is_free' => $isFree]); /* * Store the ad's images */ if ($request->has('images')) { $imagesArr = []; foreach ($request['images'] as $image) { $imagePaths = explode('|', $image); $imagesArr[] = ['ad_id' => $ad->id, 'small' => $imagePaths[0], 'big' => $imagePaths[1]]; } AdImage::insert($imagesArr); } /* * Update the ad's auto extra properties if received */ if ($request->has('make')) { $autoExtraProperties = AutoExtraProperties::where('ad_id', $ad->id)->first(); $autoExtraProperties->update(['model_id' => $request['model'], 'year' => $request['year'], 'capacity' => $request['capacity'], 'engine_type' => $request['engine_type'], 'transmission' => $request['transmission'], 'mileage' => $request['mileage'], 'power' => $request['power']]); } /* * Update the ad's realty extra properties if received */ if ($request->has('type_of_ad')) { $realtyExtraProperties = RealtyExtraProperties::where('ad_id', $ad->id)->first(); $realtyExtraProperties->update(['type' => $request['type_of_ad'], 'lease' => $request['lease'], 'num_of_rooms' => $request['num_of_rooms'], 'square' => $request['square'], 'floor' => $request['floor'], 'num_of_floors' => $request['num_of_floors']]); } return view('publish', ['categories' => Category::getAll(), 'regions' => Region::getAllWithCities(), 'ad' => $ad, 'updated' => true]); } else { return redirect('/'); } }
public function contacts() { return view('static.contacts', ['categories' => Category::getAll()]); }