I'm trying to reuse a variable from one function to another.
public function function1($id)
{
$data1 = DB::table('table1 as t1')
->select("t1.name", "t1.address", "t2.designation")
->join('table2 as t2', 't1.name', '=', 't2.name')
->where('t2.u_id', $id)
->get();
//dd($data1); //Getting data.
$data2 = Model::select('service_name', 'service_qty')->where('u_id', $id)->get();
//dd($data2); //Getting data.
$this->function2($id, $data1, $data2);
return response()->json(array(
'data1' => $data1,
'data2' => $data2
));
}
public function function2($id, $data1, $data2)
{
return response()->json(array(
'data1' => $data1,
'data2' => $data2
));
}
But it's throwing an error.
Too few arguments to function App\Http\Controllers\MyController::function2(), 1 passed and exactly 3 expected
I'm suspecting it's an route parameter issue.
Route::get('getData/{id}', 'MyController@function2');
Or a more elegant way to do this?