-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
188 changed files
with
9,620 additions
and
9,281 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use App\Models\County; | ||
use Illuminate\Database\Eloquent\Relations\MorphToMany; | ||
|
||
trait HasCounties | ||
{ | ||
public function counties(): MorphToMany | ||
{ | ||
return $this->morphToMany(County::class, 'model', 'model_has_counties', 'model_id'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Str; | ||
|
||
trait HasUuid | ||
{ | ||
public static function bootHasUuid() | ||
{ | ||
// Generate UUID if none provided | ||
static::creating(function (Model $model) { | ||
if (! $model->uuid) { | ||
$model->uuid = (string) Str::orderedUuid(); | ||
} | ||
}); | ||
|
||
// Make sure UUIDs can't be changed | ||
static::updating(function (Model $model) { | ||
$originalUuid = $model->getOriginal('uuid'); | ||
|
||
if ( | ||
! \is_null($originalUuid) && | ||
$originalUuid !== $model->uuid | ||
) { | ||
$model->uuid = $originalUuid; | ||
} | ||
}); | ||
} | ||
|
||
public function scopeWhereUuid(Builder $query, string $uuid): Builder | ||
{ | ||
return $query->where('uuid', $uuid); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use App\Models\Volunteer; | ||
use App\Models\VolunteerRequest; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Relations\MorphToMany; | ||
|
||
trait HasVolunteers | ||
{ | ||
public function volunteers(): MorphToMany | ||
{ | ||
return $this->morphToMany(Volunteer::class, 'model', 'model_has_volunteers', 'model_id') | ||
->using(VolunteerRequest::class) | ||
->withTimestamps() | ||
->withPivot('status'); | ||
} | ||
|
||
public function scopeWhereHasVolunteers(Builder $query): Builder | ||
{ | ||
return $query->whereHas('volunteers'); | ||
} | ||
|
||
public function scopeWhereDoesntHaveVolunteers(Builder $query): Builder | ||
{ | ||
return $query->whereDoesntHave('volunteers'); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.