繁体   English   中英

背包laravel-使用$ _GET参数预选选择过滤器

[英]backpack laravel - preselect select filter with $_GET param

我有一个Document and Post(针对该文档)背包CRUD资源。 我想在发布数据表中创建一个按钮,以便当我单击该按钮时,它将链接到该发布的文档。

这是我的模特帖子

class Post extends Model{
    ...
    function allDocuments(){
        return '<a href="/admin/document/?post_id='.$this->id.'" class="btn btn-xs btn-default"><i class="fa fa-list"></i> Documents</a>';
    }
}

这是我的PostCrudController

class PostCrudController extends CrudController{
    ...
    $this->crud->addButtonFromModelFunction('line', 'all_documents', 'allDocuments', 'beginning');

}

那就是我的DocumentCrudController

class DocumentCrudController extends CrudController{
    ...
            $this->crud->addFilter([ 
              'name' => 'post_id',
              'type' => 'select2',
              'label'=> 'Post To Filter',
              'value' => $_GET['post_id'] // <------- Hoped this works, but doesn't
            ], function() {
                $condos = [];
                foreach(Post::get() as $c){
                    $condos[$c->id] = $c->title." >> ".$c->category->name." >> ".$c->category->condomimium->name;
                }
                return $condos;
            }, function($value) { // if the filter is active
                $this->crud->addClause('where', 'post_id', $value);
            });
}

我已经看到背包数据表使用带有参数(在我的情况下为post_id )的POST请求来过滤数据表,但是我需要调用GET请求以预先选择具有数据表结果的过滤器。

提前致谢

为什么不在laravel中使用Request? 像这样的$request->input(post_id); 并以这种方法实例化请求

use Illuminate\Http\Request;

public function store(Request $request) { // logic here }

实际上,即使没有'value' => $_GET['post_id'] 背包会自动识别过滤器。 过滤器的名称必须与GET参数的名称匹配

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM