/**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit(Advertisement $advertisement)
 {
     $attachments = AdsAttachment::where('hash', \Session::get('advertisements_hash'))->get();
     return view('admin.advertisement.edit', compact('advertisement', 'attachments'));
 }
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('/');
 }