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 characters
/** | |
* Scope a query to only include models matching the supplied ID or UUID. | |
* Returns the model by default, or supply a second flag `false` to get the Query Builder instance. | |
* | |
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException | |
* | |
* @param \Illuminate\Database\Schema\Builder $query The Query Builder instance. | |
* @param string $uuid The UUID of the model. | |
* @param bool|true $first Returns the model by default, or set to `false` to chain for query builder. | |
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder |
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 characters
/** | |
* Scope a query to only include models matching the supplied UUID. | |
* Returns the model by default, or supply a second flag `false` to get the Query Builder instance. | |
* | |
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException | |
* | |
* @param \Illuminate\Database\Schema\Builder $query The Query Builder instance. | |
* @param string $uuid The UUID of the model. | |
* @param bool|true $first Returns the model by default, or set to `false` to chain for query builder. | |
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder |
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 characters
/** | |
* Binds creating/saving events to create UUIDs (and also prevent them from being overwritten). | |
* | |
* @return void | |
*/ | |
public static function bootUuidModel() | |
{ | |
static::creating(function ($model) { | |
// Don't let people provide their own UUIDs, we will generate a proper one. | |
$model->uuid = Uuid::uuid4()->toString(); |
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 characters
<?php | |
namespace App\Traits; | |
use Rhumsaa\Uuid\Uuid; | |
use Illuminate\Database\Eloquent\ModelNotFoundException; | |
/** | |
* Trait UuidModel | |
* @package App\Traits |
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 characters
<?php | |
namespace App\Traits; | |
use Rhumsaa\Uuid\Uuid; | |
use Illuminate\Database\Eloquent\ModelNotFoundException; | |
/** | |
* Trait UuidModel | |
* @package App\Traits |
NewerOlder