0

i want to use laravel grid add a link with product_id (not PK) to open new window with iframe-tabs for search

i have tried assign variable from grid ,but it always say

Object of class Encore\Admin\Grid\Column could not be converted to string

protected function grid()  
{

  $userModel = config('admin.database.pm_model');

  $grid = new Grid(new $userModel());
  $grid->id('ID')->sortable();
  $grid->sn(trans('admin.product_id'))->sortable();
  $product_id = $grid->sn(trans('admin.product_id'))->value();

  $grid->com_num(trans('admin.com_num'))->sortable()->link( 
      '/admin/com/search/'.$product_id,'','' );

1.how can i get $product_id from $grid->sn

2.how can i set route to other page like /admin/com/search/123 for search not edit

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
James Lin
  • 11
  • 1
  • 5

2 Answers2

0
  1. should use display

$grid->com_num(trans('admin.com_num'))->sortable()->display(function ($com_num) { return "sn}'>{$com_num}"; });

James Lin
  • 11
  • 1
  • 5
0

All you need to do is adding display() before link().

Let assume sn is your product_id field (not PK), so you can do :

protected function grid()  
{
    ...
    $grid->column('com_num', __('com_num'))->display(function (){
        return '/admin/com/search/'.$this->sn;
    })->link();
    ...
}
RedaMakhchan
  • 482
  • 3
  • 9