<?php
namespace App\Controller\FrontEnd;
use App\classe\Search;
use App\Form\SearchType;
use App\Repository\Admin\PropertyRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
#[Route('/', name: 'frontend_home')]
public function index(PropertyRepository $repository, Request $request): Response
{
$property = $repository->findBy(array(),orderBy: ["createdAt"=>"DESC"], limit: 6 );
$search = new Search();
$form = $this->createForm(SearchType::class, $search);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$property = $property = $repository->findWidthSearch($search);
}
return $this->render('front_end/home/index.html.twig', [
'controller_name' => 'Home',
'property'=>$property,
'propertyTosel'=>$repository->findBy(["isToSale"=>1],orderBy: ["createdAt"=>"DESC"],limit: 6),
'propertyTorent'=>$repository->findBy(["isRent"=>1],orderBy: ["createdAt"=>"DESC"], limit: 6),
'Form'=>$form->createView()
]);
}
}