/** * Store a newly created resource in storage. * * @return Response */ public function store(Advertisement $ad, AdvertisementRequest $request) { $attachment = ImageUploadFacade::image($request->file('attachment')); $ad->fill($request->all())->attachment()->associate($attachment); $ad->save(); return redirect()->route('admin.advertisement.index'); }
public function sell() { $categories = Category::lists('name', 'id'); if (Request::isMethod('post')) { $rules = ['name' => 'required', 'description' => 'required', 'category' => 'required', 'file1' => 'required|mimes:jpeg,bmp,png', 'file2' => 'required|mimes:jpeg,bmp,png']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::to('piac/eladok')->withErrors($messages)->withInput(); } else { $adv = new Advertisement(); $adv->name = Input::get('name'); $adv->description = Input::get('description'); $adv->category_id = Input::get('category'); $adv->visible_from = Input::get('visible_from'); $adv->visible_until = Input::get('visible_until'); $adv->user_id = Auth::id(); $adv->seo_url = Helper::lake_directory(Input::get('name')); $adv->save(); if (Input::hasFile('file1') && Input::hasFile('file2')) { $files = []; $files[] = Input::file('file1'); $files[] = Input::file('file2'); $files[] = Input::file('file3'); $files[] = Input::file('file4'); $files[] = Input::file('file5'); foreach ($files as $key => $file) { $directory = 'USER_' . Auth::id() . '/' . $adv->id; $tmpFilePath = $_SERVER['DOCUMENT_ROOT'] . '/images/advertisements/' . $directory . '/'; if ($file) { $tmpFileName = time() . '-' . $file->getClientOriginalName(); $file->move($tmpFilePath, $tmpFileName); $advImg = new AdvertisementImage(); $advImg->advertisement_id = $adv->id; $advImg->url = $directory . '/' . $tmpFileName; $advImg->save(); } } } Session::flash('message', 'Köszönjük!.Egyik adminisztrátorunk engedélyezni fogja hírdetésedet a következő 30 percben.'); return Redirect::to('/'); } } return view('market.sell', ['categories' => $categories]); }
/** * 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('/'); }
public function post_create() { $input = Input::all(); $validator = Validator::make($input, $this->rules); if ($validator->fails()) { return redirect()->back()->with('error', $validator->errors()->all())->withInput(); } $advertisement = new Advertisement(); $advertisement->title = $input['title']; $advertisement->category_id = $input['category']; $advertisement->description = $input['description']; $advertisement->user_id = Auth::user()->id; $advertisement->save(); $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' => Config::get('app.locale'), 'category' => $category, 'url' => $slug])->with('success', trans('message.advertisement_add')); }
/** * * @param int $id * @return Response * @Get("/{id}/approve",as="admin.advertisement.approve") */ public function approve(Advertisement $advertisement) { $advertisement->approved = 1; $advertisement->save(); return \Redirect::back(); }