/** * Decodes an ID value to the numeric string value * * @param string $value * @param string $config * * @return int */ public static function decode($value, $config = 'main') { $id = Hashids::connection($config)->decode($value); return isset($id[0]) ? $id[0] : 0; }
/** * Boot Eloquent Hashids trait for the model. * * @return void */ public static function bootEloquentHashids() { static::created(function (Model $model) { $model->{static::getHashidColumn($model)} = Hashids::connection(static::getHashidConnection($model))->encode(static::getHashidEncodingValue($model)); $model->save(); }); }
/** * Define the route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * * @return void */ public function boot(Router $router) { parent::boot($router); $router->bind('analysis', function ($value) { $decoded = Hashids::connection('analyses')->decode($value); if (isset($decoded[0]) && is_numeric($decoded[0]) && ($analysis = Analysis::find($decoded[0]))) { return $analysis; } throw new NotFoundHttpException('Analysis not found.'); }); $router->bind('repo', function ($value) { if (is_numeric($value) && ($repo = Repo::find($value))) { return $repo; } throw new NotFoundHttpException('Repo not found.'); }); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $hash = Hashids::connection('hashtag')->encode(time()); return Usuarios::create(['twitter_id' => $data['twitter_id'], 'socket_id' => $hash]); }
/** * Get the analysis hashids id. * * @return string */ protected function id() { return Hashids::connection('analyses')->encode($this->wrappedObject->id); }