Laravel Türkiye Discord Kanalı Forumda kod paylaşılırken dikkat edilmesi gerekenler!Birlikte proje geliştirmek ister misiniz?

Bu sonucu daha kısa bir kod ile alabilirmiyiz?
Auth role "Super Users" değilse sonuca dahil etme

        if (Auth::user()->hasRole('Super Users')) {
            $roles = Role::all()->pluck('title', 'id');
        } else {
            $roles = Role::where('title', '<>', 'Super Users')->pluck('title', 'id');
        }

    AbdulkadirLevent Bu haliyle kısaltamazsınız. Bu şekilde de kullanmamanız lazım. Şu şekilde olabilir mesela (çok hızlı yazıyorum, sadece örnek olsun diye, mimari hatalar olabilir):

    <?php
    
    namespace App\Repositories;
    
    use App\Role;
    
    class RoleRepository
    {
        public $model;
        
        public function __construct(Role $role)
        {
            $this->model = $role;
        }
    
        public function all()
        {
            return $this->model->get();
        }
    
        public function allExceptSuperUsers()
        {
            return $this->model->where('name', '<>', 'Super Users')->get();
        }
    }
    <?php
    
    namespace App\Services;
    
    use App\Repositories\RoleRepository;
    use Illuminate\Contracts\Auth\Guard;
    
    class RoleService
    {
        public $roleRepository;
    
        public $guard;
    
        public $user;
    
        public function __construct(RoleRepository $roleRepository, Guard $guard)
        {
            $this->roleRepository = $roleRepository;
            $this->guard = $guard;
            $this->user = $guard->user();
        }
    
        public function getAppropriateRoles()
        {
            if ($this->user->hasRole('Super Users')) {
                return $this->roleRepository->all();
            } else {
                return $this->roleRepository->allExceptSuperUsers();
            }
        }
    }

    Sonrasında kullanmak istediğiniz yerde mesela:

    
    <?php
    
    namespace App\Http\Controllers;
    
    use App\Services\RoleService;
    use Illuminate\Http\Request;
    
    class UserController extends Controller
    {
        public $roleService;
    
        public function __construct(RoleService $roleService)
        {
            $this->roleService = $roleService;
        }
    
        public function index()
        {
            // Bakın kısaldı ¯\_(ツ)_/¯
            $roles = $this->roleService->getAppropriateRoles()->pluck('title','id');
            
            //...
        }
    }

      mgsmus 😀 Allahtan kısaldı ha 😁
      Hocam çok sık kullanacağım birşey olmadığı için bu şekilde kullandım.
      Teşekkür ederim...