1
0
mirror of https://github.com/flarum/core.git synced 2025-10-20 03:06:07 +02:00

Add group management actions to API

This commit is contained in:
Toby Zerner
2015-07-31 20:10:49 +09:30
parent 6641af3ac3
commit cea8e7f567
21 changed files with 684 additions and 58 deletions

View File

@@ -0,0 +1,50 @@
<?php namespace Flarum\Core\Groups;
use Flarum\Core\Users\User;
use Illuminate\Database\Eloquent\Builder;
class GroupRepository
{
/**
* Get a new query builder for the groups table.
*
* @return Builder
*/
public function query()
{
return User::query();
}
/**
* Find a user by ID, optionally making sure it is visible to a certain
* user, or throw an exception.
*
* @param int $id
* @param User $actor
* @return Group
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function findOrFail($id, User $actor = null)
{
$query = Group::where('id', $id);
return $this->scopeVisibleTo($query, $actor)->firstOrFail();
}
/**
* Scope a query to only include records that are visible to a user.
*
* @param Builder $query
* @param User $actor
* @return Builder
*/
protected function scopeVisibleTo(Builder $query, User $actor = null)
{
if ($actor !== null) {
$query->whereVisibleTo($actor);
}
return $query;
}
}