I get an error
Cannot use object of type stdClass as array on controller
Below is my controller
public function showIndex()
{
$data['news'] = News::getAll();
foreach ($data['news'] as $key => $value) {
$data['news'][$key]['category'] = News::getCategory($value->id_berita);
}
return View::make('pages.news.main')
->with('title', 'News')
->with($data);
}
This is my model
public static function getAll()
{
$queryResult = DB::table('berita')
->leftJoin('admin', 'berita.post_author', '=', 'admin.id')
->select('id_berita', 'judul', 'post_date', 'aktif', 'fullname', 'post_author')
->orderBy('id_berita', 'desc')
->paginate(3);
return $queryResult;
}
public static function getCategory()
{
$queryResult = DB::table('news_in_category')
->join('menu_website', 'menu_website.id', '=', 'news_in_category.category_id')
->select('menu_website.id', 'title')
->get();
return $queryResult;
}
and this is my view
@if ($news)
@foreach ($news as $key => $value)
@if ($news->category)
@foreach ($news->category as $key_cat => $cat)
{{ $cat->id }}
@endforeach
@endif
@endforeach
@endif
For every news have one on more than one category, How can I fix this problem ? Please help me. I am using laravel 4