title: Laravel Controller - call function inside another function
body: <p>What is the best way to remove duplicate codes from Laravel Controller? In my particular case, I have Blog Controller where are multiple functions for each of sub-pages (index page, about, contact, single post page...). In any of those functions I have some code which is repeated. Can I create a special function which then I could call into any of function?</p>
  
  <pre><code>class BlogController extends Controller {
  
      public function getIndex() {
          $blogs = Blog::orderBy('id', 'desc')-&gt;where('status', '1')-&gt;paginate(3);
          return view('index-page')-&gt;withBlogs($blogs);
      }
  
      public function getAbout() {
          $blogs = Blog::orderBy('id', 'desc')-&gt;where('status', '1')-&gt;paginate(3);
          return view('about-page')-&gt;withBlogs($blogs);
      }
  
  }
  </code></pre>
  
  <p>And now, I want remove duplicate code with creating a special function (my code is only example, the real repeated code is much longer). Is that even possible? Is there some other way except creating another function? Maybe I can create something like function.php in Wordpress?</p>