You can create a helper file in the application directory. eg. MethodHelper.php
In this file you can specify the method that you want to use anywhere. For instance,
<?php namespace App; class MethodHelper { public static function reusableMethod() {
You can use this method anywhere by using the namespace and calling the method. In the above example, for example. Namespace:
The method call function will look like this:
MethodHelper::reusableMethod();
You can also send parameters based on your functional requirements. In your example. could you
public function showSearchResults(Request $req){
instead of reusableMethod (). Your call will be as follows:
MethodHelper::showSearchResults($req);
source share