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?
You can pass variables like this
// BaseController
protected $data = array();
// Controller
$this->data = array(
'variable' => $variable,
// ...
);
return View::make('example', $this->data);
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.
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community