Last active
July 11, 2020 11:53
-
-
Save shibbirweb/0c0bd2094dfb4fd3c723a4c511a6bc4b to your computer and use it in GitHub Desktop.
Add Helper Service Provider in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // store file and absolute url link generator | |
| if (!function_exists('dynamic_asset')){ | |
| function dynamic_asset($link){ | |
| // if absolute url | |
| if (!$link){ | |
| return asset(config('asset.default_author_thumbnail')); | |
| } else if (\Illuminate\Support\Str::startsWith($link, ['http://', 'https://'])){ | |
| return $link; | |
| }else{ | |
| return \Illuminate\Support\Facades\Storage::url($link); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if (! function_exists('paginateSerial')){ | |
| //get the serial number of pagination | |
| function paginatedSerial($data) | |
| { | |
| return $data->perPage() * ($data->currentPage() - 1); | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Providers; | |
| use Illuminate\Support\ServiceProvider; | |
| class HelperServiceProvider extends ServiceProvider | |
| { | |
| /** | |
| * Register services. | |
| * | |
| * @return void | |
| */ | |
| public function register() | |
| { | |
| // require all php files in Helpers directory | |
| foreach (glob(app_path().'/Helpers/*.php') as $filename){ | |
| require_once($filename); | |
| } | |
| } | |
| /** | |
| * Bootstrap services. | |
| * | |
| * @return void | |
| */ | |
| public function boot() | |
| { | |
| // | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment