App\Services\Repositories\UserRepository::get PHP Méthode

get() public méthode

Get a user from repository and cache it.
public get ( string $identification, string $type = 'uid' ) : mixed
$identification string
$type string
Résultat mixed
    public function get($identification, $type = 'uid')
    {
        if (!$this->has($identification, $type)) {
            if ($type == "username") {
                $player = Player::where('player_name', $identification)->first();
                if ($player) {
                    $identification = $player->uid;
                    $type = "uid";
                } else {
                    return null;
                }
            }
            $user = User::where($type, $identification)->first();
            if ($user) {
                $this->set($user->uid, $user);
                return $user;
            }
        }
        return Arr::get($this->items, $identification, null);
    }

Usage Example

 public function index(Request $request, UserRepository $users)
 {
     $category = $request->input('category', 'skin');
     $page = $request->input('page', 1);
     $page = $page <= 0 ? 1 : $page;
     $q = $request->input('q', null);
     $items = [];
     if ($q) {
         foreach (['skin', 'cape'] as $category) {
             // do search
             foreach ($this->closet->getItems($category) as $item) {
                 if (strstr($item->name, $q)) {
                     $items[$category][] = $item;
                 }
             }
         }
     } else {
         $items['skin'] = $this->closet->getItems('skin');
         $items['cape'] = $this->closet->getItems('cape');
     }
     // pagination
     $total_pages = [];
     foreach ($items as $key => $value) {
         $total_pages[] = ceil(count($items[$key]) / 6);
         $items[$key] = array_slice($value, ($page - 1) * 6, 6);
     }
     return view('user.closet')->with('items', $items)->with('page', $page)->with('q', $q)->with('category', $category)->with('total_pages', max($total_pages))->with('user', $users->get(session('uid')));
 }
All Usage Examples Of App\Services\Repositories\UserRepository::get