Ejemplo n.º 1
0
 public function my_answer($locale)
 {
     $user = Auth::user();
     $advert = Advertisement::where('published', 1)->whereHas('comments', function ($q) use($user) {
         $q->where('user_id', $user->id);
     })->has('category')->orderBy('created_at', 'desc')->paginate(20);
     return view('site.profile.my_answer')->with('advert', $advert);
 }
Ejemplo n.º 2
0
 /**
  * Insert advertisement to database
  */
 public function flush(AdvertisementRequest $request)
 {
     // flag top = 0 into all ads, and flag = 1 in last ad
     $ads_top = Advertisement::where('top', '=', 1)->get();
     foreach ($ads_top as $at) {
         $at->top = 0;
         $at->update();
     }
     $hash = Session::get('advertisements_hash');
     $attachmentsNames = AdsAttachment::where('hash', $hash)->get()->toArray();
     $ads = new Advertisement();
     $ads->fill($request->all());
     $ads->user_id = Auth::user()->id;
     $ads->city_id = Auth::user()->profile->city_id;
     $ads->attachment_hash = $hash;
     $ads->top = 1;
     $ads->save();
     Session::forget('advertisements_hash');
     foreach ($attachmentsNames as $attachments => $attachment) {
         AdsAttachment::where('id', $attachment['id'])->update(['comment' => Input::get($attachment['id'])]);
     }
     return Redirect::to('/');
 }
Ejemplo n.º 3
0
 public function post_update($locale, $id)
 {
     $advertisement = Advertisement::where('published', 1)->where('id', $id)->first();
     if (!$advertisement || Auth::user()->id != $advertisement->user_id) {
         abort(404);
     }
     $input = Input::all();
     $validator = Validator::make($input, $this->rules);
     if ($validator->fails()) {
         return redirect()->back()->with('error', $validator->errors()->all())->withInput();
     }
     $advertisement->title = $input['title'];
     $advertisement->category_id = $input['category'];
     $advertisement->description = $input['description'];
     $advertisement->user_id = Auth::user()->id;
     $slug = Slug::make($advertisement->id . '-' . $advertisement->title);
     $advertisement->url = $slug;
     $advertisement->save();
     $category = Category::select('url')->where('id', $advertisement->category_id)->first()->url;
     return redirect()->route('advertisement', ['locale' => $locale, 'category' => $category, 'url' => $slug])->with('success', trans('message.advertisement_update'));
 }
Ejemplo n.º 4
0
 /**
  * @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());
 }