Home page display some information from other controllers, like news, article, etc. What is the best way of using other controller's method in one controller?
Suppose there is one controller called HomeController
,is it correct to instantiate a Controller class within home controller?
forexample, if I want to use NewsController
,instantiate it!?
The following code is just an example, I want to know that what is the best way to access a method or model in another controller?
class HomeController extends Controller
{
public function index()
{
$news_obj = new NewsController();
$news = $news_obj->getNews();
$article_obj = new ArticleController();
$articles = $article_obj->getArticles();
return view('template',['news'=>$news,'articles'=>$articles]);
}
}