I want to display in a loop the images associated with a specific id value from the database. How do I pass the value of an id to a function?
// Controller public function index() { $news = DB::table('news') ->where('posted', '=', 'true') ->simplePaginate(10); $photo = $this->photo($news->id); // ошибка здесь return View::make('index') ->with('news', $news) ->with('photo', $photo); } public function photo($id) { if(file_exists($id.'.jpg')) { return $id; } else { return 'default'; } } // View @foreach ($news as $news_item) {{ $news_item->id }} <img src='{{ $photo }}.jpg'> @endforeach