title: Laravel - How to get id for other function in controller
body: <p>I am beginner of laravel. I am involving in a small project and facing some issue. I want to get the id from the function 'getVoucher' in order to display it in my function 'index'. But I have tried my code at the below, I can't get any id from it. The dd displayed 'null' and I don't know any other solution. Any comments are appreciated. Thanks in advance.</p>
  <pre><code>        public function getVoucher(Request $request)
      {
          $id = $request-&gt;id;
          $voucher = Voucher::where('id','=',$id)-&gt;first();
  
          return $voucher;
  
      }
  
      public function index(Request $request)
      {
          if(session()-&gt;has('LoggedAdmin')) {
              $admin = Admin::where('id','=',session('LoggedAdmin'))-&gt;first();
              $data = [
                  'LoggedAdminInfo' =&gt; $admin
              ];
          }
  
          if ($request-&gt;ajax()) {
              $data = Voucher::latest()-&gt;get();
              return Datatables::of($data)
              -&gt;addIndexColumn()
              -&gt;addColumn('action', function($row){
                  $btn = '&lt;a href=&quot;javascript:void(0)&quot; data-toggle=&quot;tooltip&quot;  data-id=&quot;'.$row-&gt;id.'&quot; data-original-title=&quot;Display&quot; class=&quot;btn btn-sm btn-outline-light displayRecord&quot;&gt;Display&lt;/a&gt;';
  
                  $btn = $btn. '&lt;a href=&quot;javascript:void(0)&quot; data-toggle=&quot;tooltip&quot;  data-id=&quot;'.$row-&gt;id.'&quot; data-original-title=&quot;Edit&quot; class=&quot;btn btn-sm btn-outline-light editRecord&quot;&gt;Edit&lt;/a&gt;';
  
                  $btn = $btn.' &lt;a href=&quot;javascript:void(0)&quot; data-toggle=&quot;tooltip&quot;  data-id=&quot;'.$row-&gt;id.'&quot; data-original-title=&quot;Delete&quot; class=&quot;btn btn-sm btn-outline-light deleteRecord&quot;&gt;&lt;i class=&quot;far fa-trash-alt btn-outline-danger&quot;&gt;&lt;/i&gt;&lt;/a&gt;';
  
  
                  return $btn;
  
  
              })
              -&gt;rawColumns(['action'])
              -&gt;make(true);
          }
  
          $voucher = $this-&gt;getVoucher($request);
  
          $voucherId = $voucher-&gt;id;
  
          dd($voucher);
  
  
          $voucherStatus = VoucherStatus::where('voucher_id','=', $voucherId)-&gt;get();
  
          return view('pages.voucher', $data, compact('voucherStatus'));
      }
  </code></pre>