Saturday, April 8, 2017

how to create helpers file laravel5

Simple tip for simple stuff.

create folder Helpers in app directory
create file StringHelper.php in app\Helpers

<?php
namespace App\Helpers;
class StringHelper
{
public static function getCleanString($string)
{
//remove unnecessary chars
$string = str_replace(['-', ' '], '', $string);
return str_slug($string);
}
}

add any simple function in this class as static.
when you need a different helper, create new class for example YoutubeHelper.php and add there stuff you need.

usage

\App\Helpers\StringHelper::getCleanString($name)