mardi 9 janvier 2018

Datagrid - both condition branches fire

I have a following code:

public function index(ArticleRepository $articleRepository)
    {
        $this->authorize($this->prefix());
        $filterCategory = Request::get('category');

        if (!Request::ajax()) {
            // Then just return main index admin template, that will ajax-load the data
            return View::make($this->prefix('index'))
                ->with("dataSource", URL::route($this->prefix('index')));
        } else {
            // We'll use DataGrid to display admin listing, first define some basic settings
            $columns = array(
                'id',
                'title',
                'slug',
                'published',
                'translations',
                'cities',
                'faqs',
                'articleCategories',
            );
            $settings = array(
                'sort' => 'id',
                'direction' => 'asc',
                'max_results' => 20
            );

            $commonHandler = $this->articleRepo->filteredData($filterCategory);
            // And finally return DataGrid instance, that will handle all
            return DataGrid::make($commonHandler, $columns, $settings);
        }
    }

The thing that I am curious about is that the both - if and also the else part of code is fired. I guess there are maybe some redirect or something. I am not sure how the datagrid works but when I put the dd(Request::get('category')) to the if(!Request::ajax()) branch I get the data from the Url I am expecting but when I put that code to the else branch I get null. My question is why the both branches fire and if it is caused just by some redirect how do I pass these data (Reqest::get('category')) to the else branch.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire