Skip to content

Commit

Permalink
Add property image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dBaliukynas committed May 14, 2022
1 parent 8d52c03 commit 85afad8
Show file tree
Hide file tree
Showing 19 changed files with 567 additions and 726 deletions.
13 changes: 12 additions & 1 deletion app/Http/Controllers/PropertyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\Http\Request;
use App\Models\Property;
use App\Http\Requests\PropertyPostRequest;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;


class PropertyController extends Controller
{
Expand All @@ -18,6 +21,14 @@ public function index()
public function create(PropertyPostRequest $request)
{
$data = $request->validated();
if ($data['propertyImage'] != null) {
$image_name = strtolower($data['propertyName']) . '_' . 'main_image.' . $data['propertyImage']->getClientOriginalExtension();
Storage::putFileAs('public/images', $data['propertyImage'], $image_name);
} else {
$image_name = null;
}



$property = Property::create([
'name' => $data['propertyName'],
Expand All @@ -30,7 +41,7 @@ public function create(PropertyPostRequest $request)
'postcode' => $data['propertyPostcode'],
'type' => $data['propertyType'],
'price' => $data['propertyPrice'],
'image_path' => 'Test',
'image_path' => $image_name,
]);

return response()->json($property, 200);
Expand Down
11 changes: 6 additions & 5 deletions app/Http/Requests/PropertyPostRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public function rules()
return [
'propertyName' => 'required|min:2|max:40',
'propertyType' => 'required',
'propertyAddress' => 'required',
'propertyCountry' => 'required',
'propertyCity' => 'required',
'propertyRegion' => 'max:100',
'propertyPostcode' => 'max:100',
'propertyAddress' => 'required|max:100',
'propertyCountry' => 'required|max:100',
'propertyCity' => 'required|max:100',
'propertyRegion' => 'nullable|max:100',
'propertyPostcode' => 'nullable|max:100',
'propertyPrice' => 'required|max:10001',
'propertyDescription' => 'required|max:10000',
'propertyImage' => 'image|nullable|mimes:jpg,jpeg,png|max:4096'

];
}
Expand Down
Loading

0 comments on commit 85afad8

Please sign in to comment.