示例#1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, RentalUnit $rentalUnit)
 {
     //Use fill() to automatically fill in the fields
     $rentalUnit->fill(Input::all());
     $rentalUnit->save();
     return Response::json($rentalUnit);
 }
示例#2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, RentalUnit $rental, User $user)
 {
     $rating = $rental->ratings()->where('from_user', $user->id)->first();
     if ($rating == null) {
         $rating = new Rating();
     }
     $rating->fill(Input::all());
     $rating->save();
     //        $rating->avgRating = $rental->ratings()->avg('rating_points');
     return Response::json($rating);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, RentalUnit $property)
 {
     // Validation //
     $validation = Validator::make($request->all(), ['caption' => 'max:50|regex:/^[A-Za-z ]+$/', 'photo' => 'required|image|mimes:jpeg,png|min:1|max:2048']);
     // Check if it fails //
     if ($validation->fails()) {
         return Response::json($validation->errors()->getMessages(), 400);
     }
     /**
      * Upload the image
      */
     $image = new PropertyPicture();
     $file = $request->file('photo');
     $destination_path = 'propertyImages/' . $property->id . '/';
     $filename = time() . '_' . $file->getClientOriginalName();
     $filename_thumb = time() . '_thumb_' . $file->getClientOriginalName();
     /**
      * Check whether the path exists
      */
     if (!File::exists($destination_path)) {
         File::makeDirectory($destination_path);
     }
     /**
      * Save the image to the specified path under the specified name
      */
     Image::make($file->getRealPath())->resize(null, 300, function ($constraint) {
         $constraint->aspectRatio();
     })->save($destination_path . $filename_thumb);
     $file->move($destination_path, $filename);
     /**
      * Save the image into the database
      */
     $image->location = $destination_path . $filename;
     $image->thumb_location = $destination_path . $filename_thumb;
     $image->caption = $request->input('caption');
     $image->mime_type = $file->getClientMimeType();
     $property->propertyPicture()->save($image);
     return Response::json(RentalUnit::with('User')->with('PropertyPicture')->where('id', $property->id)->first());
 }
示例#4
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show(RentalUnit $rentalUnit, Comment $comment)
 {
     return Response::json($rentalUnit->comments()->where("id", $comment->getAttribute("id"))->get());
 }