Support the ongoing development of Laravel.io →
Database Views

Here is my controller:

public function stats()
	{
		$title = "Stats";
	        $stats = DB::table('stat_data')->get();
		return View::make('stats')->with('stats', $stats)->with('title',$title);
	}

Here is my route:

 Route::get('stats', 'StatController@stats');

My view is stats.blade.php

I want to pass the "stats_table" to my view because I use that data in the view.

ALSO....

I have added these Directories:

app
     Calculations
          Season1
                 stats1.php
           Season2
                  stats2.php

The stats1.php and stats2.php takes the data from the stats_data table and preforms calculations on them to get new variables. I have hundreds of variables in these files that I want to use in my stats.blade.php. I have been working on this few a for days but haven't got far.

So what is the best way to pass the stat table to the stat calculation files to perform these calculations. Then pass these hundreds of variables to my view from my controller?

Last updated 3 years ago.
0

You can pass variables like this

// BaseController
protected $data = array();

// Controller
$this->data = array(
    'variable' => $variable, 
    // ...
);

return View::make('example', $this->data);
Last updated 3 years ago.
0

If I did it that way I would be writing hundreds of variables in the array. What I did before laravel is use require_once(file) to use the variables in that file on the current page.

Last updated 3 years ago.
0

Do your Stats calculation in a Class who you can access your needed Variables over it. Then you can only Pass the Class to your View.

Last updated 3 years ago.
0

I have a sneaking suspicion that if you're trying to send hundreds of files to a view, you should organize your code a bit differently. I can't imagine a scenario where I need to display hundreds of pieces of data that wouldn't warrant organizing them into arrays, collections, or objects with properties.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

tyr5577 tyr5577 Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.