capture() public static method

Create a new Illuminate HTTP request from server variables.
public static capture ( ) : static
return static
Ejemplo n.º 1
0
 public function getData($columns = [])
 {
     // TODO: Хранить где-то колонки, а не вытаскивать их из фильтров
     if (!$columns) {
         $columns = array_keys($this->data_provider->filters());
     }
     $request = \Request::capture();
     $searches = json_decode($request->input('search'), true);
     $pagination = json_decode($request->input('pagination'), true);
     $sorting = json_decode($request->input('sorting'), true);
     if (empty($sorting)) {
         $sorting = $this->getSorting();
     }
     if (empty($pagination['items_per_page'])) {
         $limit = $this->data_provider->pagination()->getLimit();
     } else {
         $limit = $pagination['items_per_page'];
     }
     if (empty($pagination['current_page'])) {
         $page = 1;
     } else {
         $page = $pagination['current_page'];
     }
     $main_table = $this->data_provider->query()->getModel()->getTable();
     // Добавляем селекты для уникальности полей в выборке
     $this->data_provider->query()->addSelect($main_table . '.*');
     foreach ($columns as $field) {
         if (strpos($field, '.')) {
             $this->data_provider->query()->addSelect($field . ' as ' . str_replace('.', ':', $field));
         }
     }
     $this->buildQuery($searches);
     $grid['total'] = $this->data_provider->query()->count();
     $grid['limit'] = $limit;
     $grid['sorting'] = $sorting;
     // TODO: Избавиться от проверки на таблицу
     if ($sorting) {
         if (!strpos($sorting['field'], '.')) {
             $sorting['field'] = $main_table . '.' . $sorting['field'];
         }
         $this->data_provider->query()->orderBy($sorting['field'], $sorting['dir']);
     }
     // TODO: Избавиться от костыля с копированием массива
     $data = $this->data_provider->query()->take($limit)->skip(($page - 1) * $limit)->get()->toArray();
     $grid['data'] = [];
     foreach ($data as $i => $item) {
         foreach ($item as $key => $value) {
             $pairs = explode(':', $key);
             if (count($pairs) > 1) {
                 $grid['data'][$i][$pairs[0]][$pairs[1]] = $value;
             } else {
                 $grid['data'][$i][$key] = $value;
             }
         }
     }
     return $grid;
 }
Ejemplo n.º 2
0
 /**
  * FirewallMiddleware constructor.
  */
 public function __construct()
 {
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $this->remoteAddr = $_SERVER['REMOTE_ADDR'];
     }
     $this->checkSecretKey();
     if (!in_array(\Request::capture()->getRequestUri(), ['/ip-firewall'])) {
         $this->checkIP();
     }
 }
Ejemplo n.º 3
0
 /**
  * Datatables constructor.
  *
  * @param \Yajra\Datatables\Request $request
  */
 public function __construct(Request $request)
 {
     $this->request = $request->request->count() ? $request : Request::capture();
 }
Ejemplo n.º 4
0
 private function getRequestData($key, $default = null, $access_string = null)
 {
     $this->request = $this->request ?: \Request::capture();
     $data = json_decode($this->request->input($key), true);
     return $access_string ? array_get($data, $access_string, $default) : ($data ?: $default);
 }