Skip to content

Commit

Permalink
Filters
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Oct 30, 2018
1 parent 658a441 commit 620cad2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Http/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Place extends Base
*/
public function getImageAttribute()
{
return $this->images()->first();
return $this->images->first();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/resources/views/admin/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
translatable-fields="status,title"
table="places"
title="places"
:searchable="['id']"
include="images"
:searchable="['title']"
:sorting="['-id']">

<template slot="add-button">
Expand Down

0 comments on commit 620cad2

Please sign in to comment.