Support the ongoing development of Laravel.io →
Configuration Packages Architecture
Last updated 2 years ago.
0

Also, what's the general Laravel consensus on static-style helper classes?

(I imagine this is frowned on in DI land)

// App/Libraries/Hashids.php (autoloaded by composer)
<?php namespace App\Libraries;

class Hashids
{
	private static $instance;

	public static function encode($value)
	{
		return static::factory()->encode($value);
	}

	public static function decode($value)
	{
		return static::factory()->decode($value);
	}

	public static function factory()
	{
		if( ! static::$instance )
		{
			static::$instance = new \Hashids\Hashids(\Config::get('app.salt'));
		}
		return static::$instance;
	}
}

// application code
use App\Libraries\Hashids;
$hash = Hashids::encode($id);

Not good these days?

Or perfectly useable?

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.