簡體   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