Try to create a Helpers folder in these cases inside the App folder. Then namespace the helpers. ie:
A Dates helper App\Helpers\Dates.php
namespace App\Helpers;
/**
* collection of methods for working with dates.
*/
class Date
{
/**
* get the difference between 2 dates
*
* @param date $from start date
* @param date $to end date
* @param string $type the type of difference to return
* @return string or array, if type is set then a string is returned otherwise an array is returned
*/
public static function difference($from, $to, $type = null)
{
$d1 = new \DateTime($from);
$d2 = new \DateTime($to);
$diff = $d2->diff($d1);
if ($type == null) {
//return array
return $diff;
} else {
return $diff->$type;
}
}
}
Then in any class import the namespace:
use App\Helpers\Dates;
Then call the class
Dates::difference($from, $to);
This way you can create as many helper classes as you need, If you keep reusing the same classes over and over then it makes sense to create a package for them so they can be used on multiple projects.