0
$header = DB::select("SELECT COLUMN_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tableOne'");
$secheader = DB::select("SELECT COLUMN_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tableTwo'");

$variables = DB::table('tableThird')->get();
$variables = json_decode(json_encode($variables, true));
$tbHeading = json_decode(json_encode($header, true)); //json object

return view('admin/crosstabdata', compact('secheader','tbHeading','variables'));

When I print all three variables to view (crosstabdata.blade.php) file, it said:

secheader variable does not exist.

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
Sarfaraz
  • 31
  • 7

5 Answers5

0

Try this;

$header = DB::select("SELECT COLUMN_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tableOne'");
$data['secheader'] = DB::select("SELECT COLUMN_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tableTwo'");

$variables = DB::table('tableThird')->get();
$data['variables'] = json_decode(json_encode($variables, true));
$data['tbHeading'] = json_decode(json_encode($header, true));

return view('admin/crosstabdata', $data);

Hope this approach helps out.

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
petersowah
  • 728
  • 8
  • 20
0

try this way:

return View::make('admin.crosstabdata')
           ->with(compact('secheader', 'tbHeading', 'variables'));
Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
Ronak Bokaria
  • 616
  • 6
  • 6
0

Your code should work. Maybe the problem is in the view.

As an alternative, you can pass varaibles to your views like this:

$secheader = /** ... */;
$variables = /** ... */;
$tbHeading = /** ... */;

return view('admin.crosstabdata')
           ->with('secheader', $secheader)
           ->with('variables', $variables)
           ->with('tbHeading', $tbHeading);

Then in your view you can access them like $secheader, $variables & $tbHeading.

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
0

You can pass an associative array to the with() method, so your return statement can look like this:

return view('admin/crosstabdata')->with(['secheader' => $secheader, 'tbHeading' => $tbHeading, ...]);

Raed Yakoubi
  • 332
  • 3
  • 8
-1

i didn't try to pass three vatiables directly but here is a way to pass two variables

 return view('admin/crosstabdata', compact('secheader'))->with('tbHeading', $tbHeading);

also i saw this question in stack over flow i think it might help you its about making it as an array and passing it as one variable see here

Laravel - Pass more than one variable to view

RYOK
  • 473
  • 7
  • 23
  • I need multiple variable to pass into view. – Sarfaraz Jan 15 '19 at 12:00
  • will you can pass that variables throughmaking them as array and pass the array loop though it and loop each variable again and you get the resault see the link and you will understand – RYOK Jan 15 '19 at 19:11