/** * 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 */ public function scopeUuid($query, $uuid, $first = true) { $search = $query->where('uuid', $uuid); return $first ? $search->first() : $search; }