在Backpack-demo laravel中的“列表”视图中获取和传递过滤器数据

时间:2018-11-20 06:21:27

标签: dictionary filter view backpack-for-laravel

  public function setup() {

        /*
          |--------------------------------------------------------------------------
          | BASIC CRUD INFORMATION
          |--------------------------------------------------------------------------
         */
        $this->crud->setModel('App\Models\Result');
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/result');
        $this->crud->setEntityNameStrings('result', 'results');
        $value = '';
        /*
          |--------------------------------------------------------------------------
          | BASIC CRUD INFORMATION
          |--------------------------------------------------------------------------
         */


        $this->crud->addFilter([// add a "simple" filter called Draft 
            'type'  => 'dropdown',
            'name'  => 'state',
            'label' => 'State'
                ], [
            'Delhi'         => 'Delhi',
            'Uttar Pradesh' => 'Uttar Pradesh',
            'Tamil Nadu'    => 'Tamil Nadu',
            'Uttrakhand'    => 'Uttrakhand',
                ],


            $this->crud->addClause('where', 'state', 'LIKE', "%$value%");



        });
        $this->crud->addFilter([
            'type'  => 'dropdown',
            'name'  => 'parliamentary',
            'label' => 'Parliamentary'
                ], [
            'delhi'         => 'Delhi',
            'Uttar Pradesh' => 'Uttar Pradesh',
            'Tamil Nadu'    => 'Tamil Nadu',
            'Uttrakhand'    => 'Uttrakhand',
                ], 
                               function($value) { )
            $this->crud->addClause('where', 'parliamentary', 'LIKE', "%$value%");

        });
        $this->crud->addFilter([// add a "simple" filter called Draft 
            'type'  => 'dropdown',
            'name'  => 'assembly_name',
            'label' => 'Assembly Name'
                ], [
            'Narela'           => 'Narela', 'Burari'           => 'Burari', 'Timarpur'         => 'Timarpur',
            'Adarsh Nagar'     => 'Adarsh Nagar', 'Badli'            => 'Badli', 'Rithala'          => 'Rithala',
            'Bawana'           => 'Bawana', 'Mundka', 'Kirari'           => 'Kirari', 'Sultan Pur Majra' => 'Sultan Pur Majra',
            'Nangloi'          => 'Nangloi', 'Jat Mangol Puri'  => 'Jat Mangol Puri', 'Rohini'           => 'Rohini',
            'Shalimar Bagh'    => 'Shalimar Bagh', 'Shakur Basti'     => 'Shakur Basti',
            'Tri Nagar'        => 'Tri Nagar', 'Wazirpur'         => 'Wazirpur', 'Model Town'       => 'Model Town',
            'Sadar Bazar'      => 'Sadar Bazar', 'Chandni Chowk'    => 'Chandni Chowk',
            'Matia Mahal'      => 'Matia Mahal', 'Ballimaran'       => 'Ballimaran',
            'Karol Bagh'       => 'Karol Bagh', 'Patel Nagar'      => 'Patel Nagar',
            'Moti Nagar'       => 'Moti Nagar'
                ]
                , 
                function($value) { 
            $this->crud->addClause('where', 'assembly_name', $value);

        });


        $this->crud->addFilter([// add a "simple" filter called Draft 
            'type'  => 'dropdown',
            'name'  => 'name',
            'label' => 'Name'
                ], ['C L GUPTA   ADVOCATE'=>'C L GUPTA   ADVOCATE',
                    'DEEPAK KUMAR'=>'DEEPAK KUMAR',
                    'VIJENDER GUPTA'=>'VIJENDER GUPTA',
                    'SUKHBIR SINGH'=>'SUKHBIR SINGH',
                    'RAJU'=>'RAJU',
                    'SARABJIT SINGH'=>'SARABJIT SINGH',
                    'Rituraj Govind'=>'Rituraj Govind',
                    'Anil Jha'=>'Anil Jha',
                    'Pratyush Kanth'=>'Pratyush Kanth',
                    'D. N. Bhagat Kushwaha' =>'D. N. Bhagat Kushwaha',
                    'Abhinav Prajapati'=>'Abhinav Prajapati',
                    'Rajinder Kumar' =>'Rajinder Kumar'

                ], // the simple filter has no values, just the "Draft" label specified above
                               function($value) { // if the filter is active (the GET parameter "draft" exits)

           $this->crud->addClause('where', 'name', 'LIKE', "%$value%");

            });
        $this->crud->addFilter([// add a "simple" filter called Draft 
            'type'  => 'dropdown',
            'name'  => 'party_name',
            'label' => 'Party Name'
                ], [
                    'AAP'=>'AAP','BSP'=>'BSP','NDA'=>'NDA','INC'=>'INC','DMKP'=>'DMKP',
'IND'=>'IND','NCP'=>'NCP','SHIV SENA'=>'SHIV SENA','BJP'=>'BJP','NOTA'=>'NOTA'
                ], 
                               function($value) {
            $this->crud->addClause('where', 'party_name', 'LIKE', "%$value%");

        });

        $name = $this->request->input('name');
        $party_name = $this->request->input('party_name');
        $assembly_name = $this->request->input('assembly_name');
        $parliamentary = $this->request->input('parliamentary');
        $state = $this->request->input('state');
        $data =  [$state,$parliamentary,$name,$party_name];

        $query = 'SELECT * FROM `results` WHERE state like ' .$state.' AND ' 
                . 'parliamentary like '.$parliamentary.' AND '
                .'assembly_name like '.$assembly_name.' AND '
                .'party_name like '.$party_name.' AND '
                .'name like '.$name;



         //view($this->crud->getListView())->with('para',$data);

         $this->crud->addColumns([
            'state', 'parliamentary', 'assembly_name', 'area', 'party_name', 'name', 'no_of_cast_votes'
        ]);

       $this->crud->limit(5);
       //print_r($this->crud->query);
       //$this->crud->update($id, $data);


         //dd($query);

        $this->crud->removeAllButtonsFromStack('line');
        $this->crud->removeButton('create');
    } 

我是新的背包演示laravel管理仓库。 我想获取基于参数的过滤器数据,并传递到列表视图。 1.执行功能并传递数据$ value。  公共函数pass($ field,$ value){

    $query = "SELECT * FROM `results` WHERE ";

    if($field == 'state' )
        $query= $query.`state`.'='. $value.' or';
    if($field == 'parliamentary' )
        $query= $query.`parliamentary`.'='. $value.' or';
    if($field == 'assembly_name' )
        $query= $query.`assembly_name`.'='. $value.' or';
    if($field == 'area' )
        $query= $query.`area`.'='. $value.' or';
    if($field == 'party_name' )
        $query= $query.`party_name`.'='. $value.' or';
    if($field == 'name' )
        $query= $query.`name`.'='. $value .'limit 1,10';

        $datas = DB::select($query);

   view($this->crud->getListView())->with('datas',$datas);
}

请帮助?

我想在不同的过滤器上获取过滤器数据并传递给视图。是否可以在执行查询后获取过滤器或查询的值或数据

0 个答案:

没有答案