Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\JsonApi\v1\Users;
- use App\JsonApi\v1\CustomStrategy;
- use App\User;
- 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 = [
- 'role_id', 'name', 'email', 'password'
- ];
- protected $defaultPagination = [
- 'number' => 1
- ];
- protected $defaultWith = [
- 'role'
- ];
- protected $searchable = [
- 'name', 'email'
- ];
- /**
- * Adapter constructor.
- *
- * @param CustomStrategy $paging
- */
- public function __construct(CustomStrategy $paging)
- {
- parent::__construct(new User, $paging);
- }
- /**
- * @param Builder $query
- * @param Collection $filters
- * @return void
- */
- protected function filter($query, Collection $filters)
- {
- $this->filterWithScopes($query, $filters->only('name', 'email'));
- if ($term = $filters->get('search')) {
- $query->whereLike($this->searchable, $term);
- }
- }
- protected function role()
- {
- return $this->belongsTo();
- }
- protected function posts()
- {
- return $this->hasMany();
- }
- protected function comments()
- {
- return $this->hasMany();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement