diff --git a/src/Http/Controllers/ApiController.php b/src/Http/Controllers/ApiController.php index 3692766..80cbccd 100644 --- a/src/Http/Controllers/ApiController.php +++ b/src/Http/Controllers/ApiController.php @@ -3,7 +3,9 @@ namespace TypiCMS\Modules\Places\Http\Controllers; use Illuminate\Http\Request; +use Spatie\QueryBuilder\Filter; use Spatie\QueryBuilder\QueryBuilder; +use TypiCMS\Modules\Core\Filters\FilterOr; use TypiCMS\Modules\Core\Http\Controllers\BaseApiController; use TypiCMS\Modules\Files\Models\File; use TypiCMS\Modules\Places\Models\Place; @@ -19,8 +21,11 @@ public function __construct(EloquentPlace $place) public function index(Request $request) { $data = QueryBuilder::for(Place::class) + ->allowedFilters([ + Filter::custom('title', FilterOr::class), + ]) + ->allowedIncludes('files','images') ->translated($request->input('translatable_fields')) - ->with('files') ->paginate($request->input('per_page')); return $data; diff --git a/src/Models/Place.php b/src/Models/Place.php index 3f1f270..e15cad6 100644 --- a/src/Models/Place.php +++ b/src/Models/Place.php @@ -37,7 +37,7 @@ class Place extends Base */ public function getImageAttribute() { - return $this->images()->first(); + return $this->images->first(); } /** diff --git a/src/resources/views/admin/index.blade.php b/src/resources/views/admin/index.blade.php index b8069ca..0061a17 100644 --- a/src/resources/views/admin/index.blade.php +++ b/src/resources/views/admin/index.blade.php @@ -11,7 +11,8 @@ translatable-fields="status,title" table="places" title="places" - :searchable="['id']" + include="images" + :searchable="['title']" :sorting="['-id']">