예제 #1
0
 /**
  * Creates a new Listing model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Listing();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->listing_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  * POST /listings
  *
  * @return Response
  */
 public function store()
 {
     $data = Input::all();
     //unset all empty control
     foreach ($data as $key => $value) {
         if ($value == "") {
             unset($data[$key]);
         }
     }
     $listing = new Listing();
     if ($listing->validate($data)) {
         $listing->fill($data);
         $listing->save();
         $user = Auth::user();
         if ($user->seller != null) {
             $listing->seller()->associate($user->seller);
             $listing->save();
         } elseif ($user->broker != null) {
             $listing->broker()->associate($user->broker);
             $listing->save();
         }
         $files = Input::file('photos');
         foreach ($files as $file) {
             if ($file != null && $file->isValid()) {
                 $lp = new ListingPhoto();
                 $lp->photo_url = 'listings/' . $listing->id . '/' . time() . $file->getClientOriginalName();
                 $file->move(public_path('files/listings/' . $listing->id), $lp->photo_url);
                 $lp->listing()->associate($listing);
                 $lp->save();
             }
         }
         return View::make(Auth::user()->role->name . '.listings.add_photos')->withListing($listing)->withSuccess('<strong>Congratulations. Your listing has been created successfully and will be available once verified by admin.</strong>');
     }
     Input::flash();
     return View::make(Auth::user()->role->name . '.listings.create')->withErrors($listing->getValidator());
 }
예제 #3
0
 /**
  * Unapproves a listing
  * @param  Listing $listing The listing to approve/unapprove
  * @return Response
  */
 public function unapprove($listing)
 {
     $listing->verified = 0;
     $listing->save();
     if (Request::ajax()) {
         return Response::json($listing);
     }
     return View::make('admin.listings')->withUnapprove(true);
 }