Beispiel #1
0
 /**
  * @param QueryState $queryState
  */
 function __construct(QueryState $queryState, $disableFilters = false)
 {
     parent::__construct();
     if (is_null($this->getRouter())) {
         $disableFilters = true;
     }
     $this->queryState = $queryState;
     # if isnt 'get' request add csrf filter
     $this->beforeFilter('csrf', ['on' => ['post', 'put', 'patch', 'delete']]);
     if (!$disableFilters) {
         # if there is {model} in route we autoinit it
         $this->beforeFilter(function (Route $route, Request $request) {
             if ($model = $route->parameter('model')) {
                 $this->modelName = $model;
                 $this->getModelItem();
                 $this->modelRepository = App::make('SleepingOwl\\Admin\\Repositories\\Interfaces\\ModelRepositoryInterface', ['modelItem' => $this->modelItem, 'request' => $request]);
                 $this->queryState->setPrefix($model);
             }
         });
     }
 }
Beispiel #2
0
 /** @test */
 public function it_saves_and_loads_query_state()
 {
     $request = Mockery::mock('Illuminate\\Http\\Request');
     $request->shouldReceive('query')->once()->andReturn(['name' => 'value']);
     $session = Mockery::mock('Illuminate\\Session\\Store');
     $session->shouldReceive('set')->with('model_name.index.query', ['name' => 'value'])->once();
     $session->shouldReceive('get')->with('model_name.index.query')->once()->andReturn(['name' => 'value']);
     $queryState = new QueryState($session, $request);
     $queryState->setPrefix('model_name');
     $queryState->save();
     $state = $queryState->load();
     $this->assertEquals(['name' => 'value'], $state);
 }