Is it possible to create a function in the Controller.php file and then use it in the controllers? I try to do it and I get the error:
Method [findArticleById] does not exist on [App\Http\Controllers\ArticlesController].
The function in Controller.php:
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
private function findArticleById($id)
{
return Article::where('id', $id)->firstOrFail();
}
}
The controller:
public function show($id)
{
$article = $this->findArticleById($id);
addVisitCountToArticle($article);
return view('articles.item.show', compact('article'));
}