Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function handle(ServerRequestInterface $request)
 {
     $this->assertAdmin($request->getAttribute('actor'));
     $order = array_get($request->getParsedBody(), 'order');
     Tag::query()->update(['position' => null, 'parent_id' => null]);
     foreach ($order as $i => $parent) {
         $parentId = array_get($parent, 'id');
         Tag::where('id', $parentId)->update(['position' => $i]);
         if (isset($parent['children']) && is_array($parent['children'])) {
             foreach ($parent['children'] as $j => $childId) {
                 Tag::where('id', $childId)->update(['position' => $j, 'parent_id' => $parentId]);
             }
         }
     }
     return new EmptyResponse(204);
 }
Ejemplo n.º 2
0
 public function handle(Request $request)
 {
     if (!$request->actor->isAdmin()) {
         throw new PermissionDeniedException();
     }
     $order = $request->get('order');
     Tag::query()->update(['position' => null, 'parent_id' => null]);
     foreach ($order as $i => $parent) {
         $parentId = array_get($parent, 'id');
         Tag::where('id', $parentId)->update(['position' => $i]);
         if (isset($parent['children']) && is_array($parent['children'])) {
             foreach ($parent['children'] as $j => $childId) {
                 Tag::where('id', $childId)->update(['position' => $j, 'parent_id' => $parentId]);
             }
         }
     }
     return new EmptyResponse(204);
 }
Ejemplo n.º 3
0
 /**
  * Find all tags, optionally making sure they are visible to a
  * certain user.
  *
  * @param User|null $user
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function all(User $user = null)
 {
     $query = Tag::query();
     return $this->scopeVisibleTo($query, $user)->get();
 }