Example #1
0
 /**
  * Display the contact page to prepare and send an email.
  *
  * @param Request $request
  * @param         $model
  * @param         $id
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function contactModel(Request $request, $model, $id)
 {
     //first get the username of the logged in user
     $username = Helper::navbarUsername();
     //determine what model to use and what data to fetch
     $data = $this->_getModelAndId($model, $id, true);
     //something went wrong, redirect
     if (!$data) {
         return redirect()->back()->with(['error' => 'This ' . $model . ' does not exist!']);
     }
     $form = $this->formBuilder->create('App\\Http\\Forms\\ContactForm', ['method' => 'POST', 'url' => route('contact.email.posted')]);
     $form->add('model', 'hidden', ['value' => $model]);
     $form->add('id', 'hidden', ['value' => $id]);
     $form->add('send', 'submit', ['label' => 'Send this message', 'attr' => ['class' => 'btn btn-primary btn-block']]);
     if (isset($request['classified'])) {
         $add = Classified::whereId($request['classified'])->first();
         $title = 'Re: ' . str_limit($add->title, 34);
         $form->modify('subject', 'text', ['default_value' => $title]);
     }
     return view('contact.contact_' . $model, compact('username', 'model', 'data', 'form'));
 }
Example #2
0
 /**
  * Authorize the upload action of a picture album
  * see the route list for details
  *
  * @param $model
  * @param $model_id
  * @param $id
  *
  * @return bool
  */
 private function _authorize($model, $model_id, $id)
 {
     switch ($model) {
         case 'user':
             if ($id != 'new') {
                 $this->album = Album::where('id', $id)->first();
                 session(['album_id' => null]);
             } else {
                 if (session('album_id') && session('album_id') != null) {
                     $this->album = Album::where('id', session('album_id'))->first();
                 } else {
                     $this->makeNewAlbum();
                     Auth::user()->albums()->save($this->album);
                     $this->album->update(['user_id' => Auth::id()]);
                 }
             }
             break;
         case 'article':
             $this->article = Article::whereId($id)->first();
             if (!($this->album = Album::where('albumable_id', $id)->get()->first())) {
                 $this->makeNewAlbum();
                 $this->article->albums()->save($this->album);
             }
             break;
         case 'profession':
             $this->profession = Profession::whereId($id)->first();
             if (!($this->album = Album::where('albumable_id', $id)->get()->first())) {
                 $this->makeNewAlbum();
                 $this->profession->albums()->save($this->album);
             }
             break;
         case 'site':
             $this->site = Site::whereId($model_id)->first();
             if (!($this->album = Album::where('id', $id)->first())) {
                 if (!$this->site->albums->last()) {
                     $this->makeNewAlbum();
                     $this->site->albums()->save($this->site);
                 }
             }
             break;
         case 'classified':
             $this->classified = Classified::whereId($id)->first();
             if (!($this->classified = Album::where('albumable_id', $id)->get()->first())) {
                 $this->makeNewAlbum();
                 $this->classified->albums()->save($this->album);
             }
             break;
     }
     //session(['album_id' => $this->album->id]);
     return true;
 }
Example #3
0
 /**
  * @param $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $classified = Classified::whereId($id)->first();
     Helper::allow('classified-destroy', $classified);
     $classified->delete();
     return redirect()->back()->with(['success' => 'Your classified ad has been deleted']);
 }