Browse Source

Ajoute la recherche par commentaire

laravel_8
Clement 11 months ago
parent
commit
42ab41af8c
  1. 5
      app/Home.php
  2. 2
      app/Http/Controllers/HomeController.php
  3. 3
      resources/views/homes/home.blade.php

5
app/Home.php

@ -27,6 +27,11 @@ class Home extends Model implements Feedable
return Str::words($this->description, 10);
}
public function scopeComment(QueryBuilder $query, $comment): QueryBuilder
{
return $query->where('comment', 'LIKE', '%'.$comment.'%');
}
public function scopePriceMax(QueryBuilder $query, $price): QueryBuilder
{
return $query->where('price', '<=', $price);

2
app/Http/Controllers/HomeController.php

@ -19,6 +19,8 @@ class HomeController extends Controller
{
$homes = QueryBuilder::for(Home::class)
->allowedFilters([
AllowedFilter::scope('comment'),
AllowedFilter::scope('price_min'),
AllowedFilter::scope('price_max'),

3
resources/views/homes/home.blade.php

@ -24,6 +24,9 @@
<div class="collapse" id="filters">
<div class="card card-body">
<form>
<div class="row form-group">
<label class="col-lg-2" for="comment">Commentaire:</label><input type="text" name="filter[comment]" id="comment">
</div>
<div class="row form-group">
<label class="col-lg-2" for="price_min">Min prix:</label><input type="number" name="filter[price_min]" id="price_min">
<label class="col-lg-2" for="price_max">Max prix:</label><input type="number" name="filter[price_max]" id="price_max">

Loading…
Cancel
Save