• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

How to initialize DataGrid with constructor parameter

Knowledge Base
2
2
393
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    ryanddao99 last edited by 22 Feb 2025, 15:02

    Hello,

    I am using Customer Document extention, there is a datagrid class with a custom contstructor.
    However, i do not know how to pass parameter value to this constructor.

    #1 DocumentController code
    $customer = $this->customerRepository->with(['addresses', 'group'])->findOrFail($id);

        if (request()->ajax()) {
            return datagrid(IndividualCustomerDocumentDataGrid::class)->process();
        }
    

    #2 datagrid class
    class IndividualCustomerDocumentDataGrid extends DataGrid
    {
    /**
    * Customer Id for getting document.
    */
    protected $customerId;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct($customerId)
    {
        $this->customerId = $customerId;
    }
    

    Thank you for taking time to read this.

    1 Reply Last reply Reply Quote 0
    • Rishabh-Webkul
      Rishabh-Webkul last edited by 27 Feb 2025, 13:20

      Hello @ryanddao99

      Whatever you want to pass inside the constructor you can get the data from request

      use something like this

      public function __construct() {
      if (request('customer_id')) {
      $this->customer = $this->customerRepository->find(request('customer_id'));
      } else {
      $this->customer = $this->customerRepository->getDefaultcustomer();
      }
      }
      

      Thanks & Regards

      1 Reply Last reply Reply Quote 0
      1 out of 2
      • First post
        1/2
        Last post