I have following trait implementation:
static function getNextHashId($class)
{
$data = DB::table("information_schema.TABLES")
->where("TABLE_SCHEMA", env('DB_DATABASE'))
->where("TABLE_NAME", with(new static)->getTable())
->pluck("AUTO_INCREMENT")[0];
return Hashids::connection($class)->encode($data);
}
But when I have many class implementing the traits, it's not efficient since I need to pass class to the method.
Class1::getNextHashId(Class1::class);
Class2::getNextHashId(Class2::class);
Is it possible to remove get class from traits? so I just need to write Class1::getNextHashId();
How can it be done?
进一步搜索后,可以通过静态绑定来完成。
return Hashids::connection(static::class)->encode($data);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.