Alimentalos/Backend

View on GitHub
relationships/src/Lists/GroupList.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace Alimentalos\Relationships\Lists;

use App\Models\Group;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

trait GroupList
{
    /**
     * Get scoped groups.
     *
     * @return LengthAwarePaginator
     */
    public function index()
    {
        return Group::where('user_uuid', authenticated()->uuid)
            ->orWhere('is_public', true)
            ->orWhereIn('uuid', authenticated()->groups->pluck('uuid')->toArray())
            ->latest()
            ->paginate(25);
    }

    /**
     * Get all groups.
     *
     * @return LengthAwarePaginator
     */
    public function all()
    {
        return Group::latest()
            ->paginate(25);
    }
}