When I run the code I get no error but the data I am trying to display is not displaying it's just blank.. can someone tell me what I'm doing wrong?
My controller:
public function openingPage($id) {
$this->getGames();
$games = $this->getGames();
return view('caseopener')->with('games',$games);
}
private function getGames() {
$games = array();
foreach ($this->data->items as $item) {
$game = new Game($item);
$games[] = array(
'id' => $game['id'],
'name' => $game['name'],
'price' => $game['price'],
'image' => $game['image'],
);
}
return $games;
}
The 'Game' Model that is used in 'getGames function':
class Game extends Model
{
private $id;
public $data;
public function __construct($id) {
parent::__construct();
$this->id = $id;
$this->data = $this->getData();
}
private function getData() {
$game = DB::table('products')->where('id', 1)->first();
if(empty($game)) return array();
return $game;
}
}
The view:
@foreach ($games as $game)
<div class="gold">$ {{ $game['price'] }}</div>
@endforeach
$this->data->itemscontain anything? Does$itemcontain anything?private function getCaseData($id) { $items = DB::table('cases')->where('id', $id)->get(); $data = @$items[0] ? $items[0] : array(); if(isset($data->items)) { $data->items = json_decode($data->items, true); }dd($this->data->items)ordd($item)?$game = DB::table('products')->where('id', 1)->first();Is always looking for the game with id 1.