I have a news controller and a pages controller. The pages controller has a method called home, which returns the view for the home page. I want to be able to display this news module on the home page.
From the pages controller, how can I call upon the data from the news controller to display a news module on the front page?
You can create static method in news controller which returns news items and call it from pages controller, for instance:
class PagesController extends BaseController(){
public function home(){
$news = NewsController::GetNews();
return View::make('home')
->with('news', $news);
}
}
class NewsController extends BaseController(){
public static function GetNews(){
$news = NewsItem::OrderBy('id', 'DESC')->take(10)->get();
return $news;
}
}