Skip to content

Commit

Permalink
显示用户角色
Browse files Browse the repository at this point in the history
  • Loading branch information
liyu001989 committed Aug 7, 2020
1 parent c312d70 commit 13c28a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/Http/Queries/TopicQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public function __construct()
{
parent::__construct(Topic::query());

$this->allowedIncludes('user', 'category')
->allowedFilters([
$this->allowedIncludes('user', 'user.roles', 'category')
->allowedFilters([
'title',
AllowedFilter::exact('category_id'),
AllowedFilter::scope('withOrder')->default('recentReplied'),
Expand Down
16 changes: 16 additions & 0 deletions app/Http/Resources/RoleResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class RoleResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
];
}
}
1 change: 1 addition & 0 deletions app/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function toArray($request)

$data['bound_phone'] = $this->resource->phone ? true : false;
$data['bound_wechat'] = ($this->resource->weixin_unionid || $this->resource->weixin_openid) ? true : false;
$data['roles'] = RoleResource::collection($this->whenloaded('roles'));

return $data;
}
Expand Down

0 comments on commit 13c28a7

Please sign in to comment.