?
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Property;
use App\Models\PropertyImage;
use App\Models\Widget;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;
class PropertyController extends Controller
{
/**
* Display a listing of the properties.
*
* @return \Illuminate\View\View
*/
public function index()
{
$properties = Property::with('images')->latest()->get();
return view('properties.index', compact('properties'));
}
/**
* Show the form for creating a new property.
*
* @return \Illuminate\View\View
*/
public function create()
{
return view('properties.create');
}
/**
* Store a newly created property in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request)
{
$validatedData = $request->validate([
'category' => 'required|string',
'type' => 'required|string',
'headline' => 'required|string',
'quote' => 'nullable|string',
'title' => 'required|string',
'subtitle' => 'nullable|string',
'highlights1' => 'nullable|string',
'highlights2' => 'nullable|string',
'highlights3' => 'nullable|string',
'highlights4' => 'nullable|string',
'highlights5' => 'nullable|string',
'highlights6' => 'nullable|string',
'videoembeedlink' => 'nullable|string',
'location' => 'required|string',
'description' => 'required|string',
'price' => 'required|numeric',
'video' => 'nullable|string',
'reranotice' => 'nullable|string',
'projectstatus' => 'required|integer|between:0,100',
]);
// Generate the slug and UUID and add them to the validated data
// $validatedData['slug'] = Str::slug($request->title . '-' . Str::random(5));
// $validatedData['uuid'] = Str::uuid();
// dd($validatedData);
// Create the property using the updated validated data
$property = Property::create($validatedData);
return redirect()->route('properties.index')->with('success', 'Property created successfully.');
}
/**
* Display the specified property.
*
* @param \App\Models\Property $property
* @return \Illuminate\View\View
*/
public function show(Property $property)
{
return view('properties.show', compact('property'));
}
public function estateShow($slug)
{
$property = $property = Property::Where('slug', $slug)->with('images')->first();
$bottomTicker = Widget::SingleDataSpecific('BottomTicker');
return view('properties.estate-show', compact('property','bottomTicker'));
}
/**
* Show the form for editing the specified property.
*
* @param \App\Models\Property $property
* @return \Illuminate\View\View
*/
public function edit(Property $property)
{
return view('properties.edit', compact('property'));
}
/**
* Update the specified property in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Property $property
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request, Property $property)
{
$validatedData = $request->validate([
'category' => 'required|string',
'type' => 'required|string',
'headline' => 'required|string',
'quote' => 'nullable|string',
'title' => 'required|string',
'subtitle' => 'nullable|string',
'highlights1' => 'nullable|string',
'highlights2' => 'nullable|string',
'highlights3' => 'nullable|string',
'highlights4' => 'nullable|string',
'highlights5' => 'nullable|string',
'highlights6' => 'nullable|string',
'videoembeedlink' => 'nullable|string',
'location' => 'required|string',
'description' => 'required|string',
'price' => 'required|numeric',
'video' => 'nullable|string',
'reranotice' => 'nullable|string',
'projectstatus' => 'required|integer|between:0,100',
]);
$property->update($validatedData);
return redirect()->route('properties.index')->with('success', 'Property updated successfully.');
}
/**
* Remove the specified property from storage.
*
* @param \App\Models\Property $property
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Property $property)
{
$property->delete();
return redirect()->route('properties.index')->with('success', 'Property deleted successfully.');
}
/**
* Handle the image and brochure upload for a property.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Property $property
* @return \Illuminate\Http\RedirectResponse
*/
public function uploadImage(Request $request, Property $property)
{
$request->validate([
'file' => 'required|file',
'type' => 'required|string',
'orderby' => 'nullable|integer',
'featured' => 'nullable|boolean',
'highlight' => 'nullable|boolean',
'primaryimage' => 'nullable|boolean',
]);
$path = $request->file('file')->store('public/property_images');
$property->images()->create([
'file_path' => Storage::url($path),
'type' => $request->input('type'),
'orderby' => $request->input('orderby'),
'featured' => $request->has('featured'),
'highlight' => $request->has('highlight'),
'primaryimage' => $request->has('primaryimage'),
]);
return back()->with('success', 'Image uploaded successfully.');
}
}