Skip to content

Instantly share code, notes, and snippets.

@shibbirweb
Last active July 11, 2020 11:53
Show Gist options
  • Select an option

  • Save shibbirweb/0c0bd2094dfb4fd3c723a4c511a6bc4b to your computer and use it in GitHub Desktop.

Select an option

Save shibbirweb/0c0bd2094dfb4fd3c723a4c511a6bc4b to your computer and use it in GitHub Desktop.
Add Helper Service Provider in Laravel
<?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);
}
}
}
<?php
if (! function_exists('paginateSerial')){
//get the serial number of pagination
function paginatedSerial($data)
{
return $data->perPage() * ($data->currentPage() - 1);
}
}
<?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