Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\JsonApi\v1\Comments;
- use App\Comment;
- use App\JsonApi\v1\CustomStrategy;
- use CloudCreativity\LaravelJsonApi\Eloquent\AbstractAdapter;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Support\Collection;
- class Adapter extends AbstractAdapter
- {
- /**
- * Mapping of JSON API attribute field names to model keys.
- *
- * @var array
- */
- protected $attributes = [];
- /**
- * Mapping of JSON API filter names to model scopes.
- *
- * @var array
- */
- protected $filterScopes = [];
- protected $fillable = [
- 'user_id', 'post_id', 'body'
- ];
- protected $defaultWith = [
- 'commentator'
- ];
- protected $defaultPagination = [
- 'number' => 1
- ];
- protected $searchable = [
- 'body'
- ];
- /**
- * Adapter constructor.
- *
- * @param CustomStrategy $paging
- */
- public function __construct(CustomStrategy $paging)
- {
- parent::__construct(new Comment, $paging);
- }
- /**
- * @param Builder $query
- * @param Collection $filters
- * @return void
- */
- protected function filter($query, Collection $filters)
- {
- $this->filterWithScopes($query, $filters->only('body'));
- if ($term = $filters->get('search')) {
- $query->whereLike($this->searchable, $term);
- }
- }
- protected function commentator()
- {
- return $this->belongsTo();
- }
- protected function post()
- {
- return $this->belongsTo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement