I have a Document and Post (for that document) Backpack CRUD resources. I want to create a button inside the post datatable so that when I click that button, it will link to the documents of that post.
this is my model post
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>';
}
}
this is my PostCrudController
class PostCrudController extends CrudController{
...
$this->crud->addButtonFromModelFunction('line', 'all_documents', 'allDocuments', 'beginning');
}
and that's my 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);
});
}
I've seen that backpack datatables uses a POST request with the parameters (in my case post_id
) to filter the datatable, but I need to call a GET request to preselect my filter with the datatable result accordingly.
thanks in advance
Why not using Request in laravel ? something like this $request->input(post_id);
and instantiate the request in the method like this
use Illuminate\Http\Request;
public function store(Request $request) { // logic here }
Actually it works even without 'value' => $_GET['post_id']
. Backpack recognizes automatically filter. The name of the filter must match to the name of the GET
param
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.