Last active
October 12, 2020 10:58
-
-
Save bolechen/ca98c08ba8574d93954bdcc3e9006e3f to your computer and use it in GitHub Desktop.
Revisions
-
bolechen revised this gist
Aug 4, 2019 . 1 changed file with 35 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,10 +16,44 @@ public function getRouteKeyName() return 'uuid'; } public static function findByUuidOrFail($uuid) { return self::whereUuid($uuid)->firstOrFail(); } /** * Eloquent scope to look for a given UUID. * * @param \Illuminate\Database\Eloquent\Builder $query * @param string $uuid The UUID to search for * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeWithUuid($query, $uuid) { return $query->where('uuid', $uuid); } /** * Eloquent scope to look for multiple given UUIDs. * * @param \Illuminate\Database\Eloquent\Builder $query * @param array $uuids The UUIDs to search for * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeWithUuids($query, array $uuids) { return $query->whereIn('uuid', $uuids); } protected static function bootHasUuid() { static::creating(function ($model) { if (!$model->uuid) { // 这里使用了 orderedUuid 方便后期分表 $model->uuid = (string) Str::orderedUuid(); } }); } } -
bolechen renamed this gist
Jul 19, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bolechen revised this gist
Jul 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function getRouteKeyName() return 'uuid'; } protected static function bootHasUuid() { static::creating(function ($model) { $model->uuid = Str::orderedUuid(); -
bolechen revised this gist
Jul 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use Illuminate\Support\Str; trait HasUuid { /** * Get the route key for the model. -
bolechen revised this gist
Apr 15, 2019 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ <?php namespace App\Traits; @@ -24,4 +23,3 @@ protected static function bootUsesUuid() }); } } -
bolechen renamed this gist
Apr 15, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bolechen created this gist
Apr 15, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ ```php <?php namespace App\Traits; use Illuminate\Support\Str; trait UsesUuid { /** * Get the route key for the model. * * @return string */ public function getRouteKeyName() { return 'uuid'; } protected static function bootUsesUuid() { static::creating(function ($model) { $model->uuid = Str::orderedUuid(); }); } } ```