当前位置: 首页>>代码示例>>PHP>>正文


PHP array_fetch函数代码示例

本文整理汇总了PHP中array_fetch函数的典型用法代码示例。如果您正苦于以下问题:PHP array_fetch函数的具体用法?PHP array_fetch怎么用?PHP array_fetch使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了array_fetch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Check if a user is logged in.
     if (!($user = $request->user())) {
         // If not, continue the request.
         return $next($request);
     }
     // Get the current route.
     $route = $request->route();
     // Get the current route actions.
     $actions = $route->getAction();
     // Check if we have any permissions to check.
     if (!($permissions = isset($actions['permissons']) ? $actions['permissons'] : null)) {
         // No permissions to check, allow access.
         return $next($request);
     }
     // Fetch all of the users permissions.
     $userPermissions = array_fetch($user->permissions()->whereIn('slug', (array) $permissions)->get()->toArray(), 'slug');
     // Ensure that the required permissions are an array.
     $permissions = (array) $permissions;
     if (isset($actions['permissions_require_all'])) {
         // If the user has EVERY permission required.
         if (count($permissions) == count($userPermissions)) {
             // Allow the request.
             return $next($request);
         }
     } else {
         if (count($userPermissions) > 0) {
             // Allow the request.
             return $next($request);
         }
     }
     // Abort the request if we reach here.
     return abort(401);
 }
开发者ID:seta-hungnh,项目名称:article-laravel5-permissions,代码行数:42,代码来源:PermissionsRequiredMiddleware.php

示例2: getAllTabsFromAllRoles

 protected function getAllTabsFromAllRoles()
 {
     $tabs = $this->roles->load('tabs')->fetch('tabs')->toArray();
     return array_map('strtolower', array_unique(array_flatten(array_map(function ($tab) {
         return array_fetch($tab, 'tab_slug');
     }, tabs))));
 }
开发者ID:Kaelcao,项目名称:colormev2,代码行数:7,代码来源:User.php

示例3: handle

 public function handle($request, Closure $next)
 {
     if (!($user = $request->user())) {
         return $next($request);
     }
     $route = $request->route();
     $actions = $route->getAction();
     if (!($permissions = isset($action['permission_title']) ? $actions['permission_title'] : null)) {
         return $next($request);
     }
     $userPermissions = array_fetch($user->permissions()->whereIn('slug', (array) $permissions)->get()->toArray(), 'slug');
     $permissions = (array) $permissions;
     if (isset($actions['permissions_require_all'])) {
         // If user has EVERY permission required.
         if (count($permissions) == count($userPermissions)) {
             // Access is granted.
             return $next($request);
         }
     } else {
         // If the user has the permission.
         if (count($userPermissions) >= 1) {
             // Access is granted and the rest of the permissions are ignored.
             return $next($request);
         }
     }
     return abort(401);
 }
开发者ID:nicegal17,项目名称:Accounting-System,代码行数:27,代码来源:PermissionsRequiredMiddleware.php

示例4: links

 public function links()
 {
     $params = [];
     $list = [];
     $extras = [];
     $new_list_length = null;
     if (is_array(last($this->route_params))) {
         $extras = array_pop($this->route_params);
     }
     $append_plain = $this->getPlainTextExtras($extras, 'append_plain', $this->items);
     $prepend_plain = $this->getPlainTextExtras($extras, 'prepend_plain', $this->items);
     foreach ($this->route_params as $param) {
         $params[] = $this->collectKeys($this->items, $param)->toArray();
     }
     $items = $this->collectKeys($this->items, $this->key);
     if (array_key_exists('truncate', $extras)) {
         $this->setCharLimit($extras['truncate']);
         $new_list_length = $this->getTruncatedList($items);
         $this->setCharLimit(null);
     }
     foreach ($items as $key => $item) {
         $str = '';
         if ($str_prepend = $this->getPlainTextReplaced($extras, 'prepend_plain', $prepend_plain, $key)) {
             $str .= $str_prepend;
         }
         $str .= '<a href="' . route($this->route, array_fetch($params, $key)) . '">';
         $str .= $item . '</a>';
         if ($str_append = $this->getPlainTextReplaced($extras, 'append_plain', $append_plain, $key)) {
             $str .= $str_append;
         }
         $list[] = $str;
     }
     return $this->listize($list, $new_list_length);
 }
开发者ID:ngangchill,项目名称:templater,代码行数:34,代码来源:ItemList.php

示例5: hasAccess

 /**
  * Get all access module from all permissions of all roles.
  *
  * @return Array of permission slugs
  */
 public function hasAccess()
 {
     $permissions = $this->roles->load('permissions')->fetch('permissions')->toArray();
     return array_map('strtolower', array_unique(array_flatten(array_map(function ($permission) {
         return array_fetch($permission, 'permission_slug');
     }, $permissions))));
 }
开发者ID:dungnh,项目名称:survey_online,代码行数:12,代码来源:User.php

示例6: makeUser

 public function makeUser($t)
 {
     $assign = array();
     $roles = array_fetch(\App\Role::all()->toArray(), 'name');
     $assign[] = $this->getIdInArray($roles, $t);
     $this->roles->attach($assign);
 }
开发者ID:deryrahma,项目名称:dokternet,代码行数:7,代码来源:User.php

示例7: getAllPermissionsFromAllRoles

 /**
  * Get all permission slugs from all permissions of all roles
  *
  * @return Array of permission slugs
  */
 protected function getAllPermissionsFromAllRoles()
 {
     $permissions = $this->roles->load('permissions')->fetch('permissions')->toArray();
     return array_map('strtolower', array_unique(array_flatten(array_map(function ($permission) {
         return array_fetch($permission, 'permission_slug');
     }, $permissions))));
 }
开发者ID:b-l4ck,项目名称:AbuseIO,代码行数:12,代码来源:User.php

示例8: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Check if a user is logged in.
     if (!($user = $request->user())) {
         return $next($request);
     }
     $route = $request->route();
     // Get the current route actions.
     $actions = $route->getAction();
     // Check if we have any permissions to check the user has.
     if (!($permissions = isset($actions['permissions']) ? $actions['permissions'] : null)) {
         // No permissions to check, allow access.
         return $next($request);
     }
     // Fetch all of the matching user permissions.
     $userPermissions = array_fetch($user->permissions()->whereIn('slug', (array) $permissions)->get()->toArray(), 'slug');
     // Turn the permissions we require into an array.
     $permissions = (array) $permissions;
     // Check if we require all permissions, or just one.
     if (isset($actions['permissions_require_all'])) {
         // If user has EVERY permission required.
         if (count($permissions) == count($userPermissions)) {
             // Access is granted.
             return $next($request);
         }
     } else {
         // If the user has the permission.
         if (count($userPermissions) >= 1) {
             // Access is granted and the rest of the permissions are ignored.
             return $next($request);
         }
     }
     // If we reach this far, the user does not have the required permissions.
     return Redirect::back();
 }
开发者ID:vjtc0n,项目名称:project,代码行数:42,代码来源:PermissionsRequiredMiddleware.php

示例9: disponible

 public static function disponible($horarios, $asignatura_id, $ciclo_id, $horas)
 {
     $ciclo = Ciclo::find($ciclo_id);
     $asignatura = Asignatura::find($asignatura_id);
     $profesores_disponibles = self::whereHas('clases', function ($q) use($ciclo_id, $horarios) {
         $q->whereHas('grupo', function ($q) use($ciclo_id) {
             $q->where('ciclo_id', '=', $ciclo_id);
         })->whereIn('horario_id', array_fetch($horarios->toArray(), 'id'));
     }, '<=', $horarios->count() - $horas)->whereHas('asignaturas', function ($q) use($asignatura) {
         $q->where('asignatura_id', '=', $asignatura->id);
     })->get();
     if ($profesores_disponibles->count() > 0) {
         return $profesores_disponibles->random();
     }
     $profesores_capacitables = Profesor::whereHas('clases', function ($q) use($ciclo_id, $horarios) {
         $q->whereHas('grupo', function ($q) use($ciclo_id) {
             $q->where('ciclo_id', '=', $ciclo_id);
         })->whereIn('horario_id', array_fetch($horarios->toArray(), 'id'));
     }, '<=', $horarios->count() - $horas)->whereDoesntHave('asignaturas', function ($q) use($asignatura) {
         $q->where('asignatura_id', '=', $asignatura->id);
     })->has('asignaturas', '<', 10)->get();
     if ($profesores_capacitables->count() > 0) {
         $profesor = $profesores_capacitables->random();
         $profesor->asignaturas()->attach($asignatura->id);
         return $profesor;
     }
     $profesor = self::crearProfesor();
     $profesor->asignaturas()->attach($asignatura->id);
     return $profesor;
 }
开发者ID:bvenegas92,项目名称:trinity-faker,代码行数:30,代码来源:Profesor.php

示例10: avanzarCiclo

 public function avanzarCiclo($ciclo_id)
 {
     $carrera = $this->carrera;
     $nombre = $carrera->clave . ' ' . ($this->cuatrimestre + 1) . substr($this->nombre, 5, 2);
     $nuevo_grupo = Grupo::create(array('nombre' => $nombre, 'carrera_id' => $carrera->id, 'ciclo_id' => $ciclo_id, 'cuatrimestre' => $this->cuatrimestre + 1));
     $nuevo_grupo->alumnos()->attach(array_fetch($this->alumnos->toArray(), 'id'));
     return $nuevo_grupo;
 }
开发者ID:bvenegas92,项目名称:trinity-faker,代码行数:8,代码来源:Grupo.php

示例11: getCategoryListById

 /**
  * Get category list by id
  *
  * @author Hein Zaw Htet
  **/
 public function getCategoryListById($id)
 {
     // $model = $this->model->find($id);
     // dd($model->categories()->id);
     $model = $this->model->find($id);
     $list = $model->categories->toArray();
     return array_fetch($list, 'id');
 }
开发者ID:eiswe,项目名称:website,代码行数:13,代码来源:BlogRepository.php

示例12: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Alle records aanvullen met gegevens welke ontbreken vanuit CSV-bestand');
     $aantal = true;
     while ($aantal != 0) {
         $rij = Data::select('id')->where('temp', '!=', 2)->take(300)->get();
         $aantal = $rij->count();
         if ($aantal > 0) {
             foreach ($rij as $ro) {
                 $r = Data::find($ro->id);
                 $r->temp = 2;
                 $r->save();
             }
         }
         $this->info($aantal);
     }
     $this->info('\'region_of_destination\' fixen...');
     $regionLeeg = Data::select('city_of_destination', 'region_of_destination')->where('region_of_destination', '')->groupBy('city_of_destination')->get();
     if ($regionLeeg->count() > 0) {
         $city = Data::select('city_of_destination', 'region_of_destination')->where('region_of_destination', '!=', '')->whereIn('city_of_destination', array_fetch($regionLeeg->toArray(), 'city_of_destination'))->groupBy('city_of_destination')->get();
         foreach ($city->toArray() as $row) {
             Data::where('city_of_destination', $row['city_of_destination'])->where('region_of_destination', '')->update(array('region_of_destination' => $row['region_of_destination'], 'slug_region_of_destination' => Str::slug($row['region_of_destination'])));
         }
     }
     /**
      * Zijn er na bovenstaande actie nog steeds regels over zonder 'region_of_destination' dan verwijderen
      */
     $rowsStillNotOK = $regionLeeg2 = Data::where('region_of_destination', '')->delete();
     if ($rowsStillNotOK > 0) {
         $this->info('\'region_of_destination\' verwijderd: ' . $rowsStillNotOK . ' accommodaties');
     }
     $this->info('\'region_of_destination\' fixen... DONE');
     /**
      * Empty slug fixing
      */
     /*$this->info('\'slug_region_of_destination\' fixen...');
     
     		$slugToFill = Data::select('id', 'region_of_destination', 'slug_region_of_destination')
     			->where('region_of_destination', '!=', '')
     			->where('slug_region_of_destination', '')
     			->get();
     
     		if ($slugToFill->count() > 0)
     		{
     			foreach ($slugToFill->toArray() as $row)
     			{
     				Data::where('id', $row['id'])->update(
     					array(
     						'slug_region_of_destination' => \Str::slug($row['region_of_destination'])
     					)
     				);
     			}
     		}
     		$this->info('\'slug_region_of_destination\' fixen... DONE');*/
     $this->call('cache:clear');
     return $this->info('Done');
 }
开发者ID:bahjaat,项目名称:daisycon,代码行数:62,代码来源:DaisyconFixData.php

示例13: isAllowedUser

 public function isAllowedUser($user_id)
 {
     $user = User::where('id', '=', $user_id)->first();
     foreach ($this->roles as $role) {
         if (in_array($role->name, array_fetch($user->roles->toArray(), 'name'))) {
             return true;
         }
     }
     return false;
 }
开发者ID:rituzy,项目名称:iblog,代码行数:10,代码来源:Album.php

示例14: getDataById

 /**
  * [getDataById description]
  * @param  integer 	$id 	policy id
  * @return array 	$datas  condition name information and count
  */
 public function getDataById($id)
 {
     $cond = ConditionPolicy::where('policy_id', '=', $id)->get(array('cond_id'));
     $cond_id = array_fetch($cond->toArray(), 'cond_id');
     $rs = DB::table('condition')->whereIn('id', $cond_id)->get(array('cond_name'));
     $datas['count'] = count($rs);
     $datas['data'] = $rs;
     $datas['id'] = $cond_id;
     return $datas;
 }
开发者ID:nattaphat,项目名称:cuse2,代码行数:15,代码来源:ConditionPolicy.php

示例15: getDataById

 /**
  * [getDataById description]
  * @param  integer 	$id 	policy id
  * @return array 	$datas  role name information and count
  */
 public function getDataById($id)
 {
     $role = RolePolicy::where('policy_id', '=', $id)->get(array('role_id'));
     $role_id = array_fetch($role->toArray(), 'role_id');
     $rs = DB::table('roles')->whereIn('id', $role_id)->get(array('role_name'));
     $datas['count'] = count($rs);
     $datas['data'] = $rs;
     $datas['id'] = $role_id;
     return $datas;
 }
开发者ID:nattaphat,项目名称:cuse2,代码行数:15,代码来源:RolePolicy.php


注:本文中的array_fetch函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。