-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
26 changed files
with
1,176 additions
and
150 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
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use App\Models\City; | ||
use App\Models\County; | ||
use Illuminate\Contracts\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
trait HasLocation | ||
{ | ||
public function initializeHasLocation(): void | ||
{ | ||
$this->fillable = array_merge($this->fillable, ['county_id', 'city_id']); | ||
} | ||
|
||
public function county(): BelongsTo | ||
{ | ||
return $this->belongsTo(County::class); | ||
} | ||
|
||
public function city(): BelongsTo | ||
{ | ||
return $this->belongsTo(City::class); | ||
} | ||
|
||
public function scopeWithLocation(Builder $query): Builder | ||
{ | ||
return $query->with('county', 'city'); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Str; | ||
|
||
trait HasUlid | ||
{ | ||
protected $ulidColumn = 'ulid'; | ||
|
||
public static function bootHasUlid() | ||
{ | ||
// Generate ULID if none provided | ||
static::creating(function (Model $model) { | ||
if (! $model->{$model->ulidColumn}) { | ||
$model->{$model->ulidColumn} = (string) Str::ulid(); | ||
} | ||
}); | ||
|
||
// Make sure ULIDs can't be changed | ||
static::updating(function (Model $model) { | ||
$originalUlid = $model->getOriginal($model->ulidColumn); | ||
|
||
if ( | ||
! \is_null($originalUlid) && | ||
$originalUlid !== $model->{$model->ulidColumn} | ||
) { | ||
$model->{$model->ulidColumn} = $originalUlid; | ||
} | ||
}); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Forms\Components; | ||
|
||
use App\Models\City; | ||
use App\Models\County; | ||
use Filament\Forms\Components\Concerns\CanBeValidated; | ||
use Filament\Forms\Components\Grid; | ||
use Filament\Forms\Components\Select; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
class Location extends Grid | ||
{ | ||
use CanBeValidated; | ||
|
||
protected bool $withCity = true; | ||
|
||
public function withoutCity(): self | ||
{ | ||
$this->withCity = false; | ||
|
||
return $this; | ||
} | ||
|
||
public function getChildComponents(): array | ||
{ | ||
return [ | ||
Select::make('county_id') | ||
->label(__('field.county')) | ||
->options(function () { | ||
return Cache::driver('array') | ||
->rememberForever( | ||
'counties', | ||
fn () => County::pluck('name', 'id') | ||
); | ||
}) | ||
->searchable() | ||
->preload() | ||
->reactive() | ||
->required($this->isRequired()) | ||
->afterStateUpdated(fn (callable $set) => $set('city_id', null)) | ||
->when(! $this->withCity, fn ($component) => $component->columnSpanFull()), | ||
|
||
Select::make('city_id') | ||
->label(__('field.city')) | ||
->searchable() | ||
->required($this->isRequired()) | ||
->getSearchResultsUsing(function (string $search, callable $get) { | ||
$countyId = (int) $get('county_id'); | ||
|
||
if (! $countyId) { | ||
return []; | ||
} | ||
|
||
return City::query() | ||
->where('county_id', $countyId) | ||
->search($search) | ||
->limit(100) | ||
->get() | ||
->pluck('name', 'id'); | ||
}) | ||
->getOptionLabelUsing(fn ($value) => City::find($value)?->name) | ||
->visible($this->withCity), | ||
]; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\MediaLibrary; | ||
|
||
use Spatie\MediaLibrary\MediaCollections\Models\Media; | ||
use Spatie\MediaLibrary\Support\PathGenerator\DefaultPathGenerator; | ||
|
||
class TenantPathGenerator extends DefaultPathGenerator | ||
{ | ||
protected function getBasePath(Media $media): string | ||
{ | ||
return collect([ | ||
filament()->getTenant()?->ulid, | ||
$media->getKey(), | ||
]) | ||
->filter() | ||
->join(\DIRECTORY_SEPARATOR); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Pages\Profile; | ||
|
||
use Filament\Forms\Components\Group; | ||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload; | ||
use Filament\Forms\Components\TextInput; | ||
use Jeffgreco13\FilamentBreezy\Livewire\PersonalInfo as BasePersonalInfo; | ||
|
||
class UserPersonalInfo extends BasePersonalInfo | ||
{ | ||
public array $only = [ | ||
'first_name', | ||
'last_name', | ||
'email', | ||
]; | ||
|
||
protected function getProfileFormSchema(): array | ||
{ | ||
$groupFields = []; | ||
|
||
if ($this->hasAvatars) { | ||
$groupFields[] = SpatieMediaLibraryFileUpload::make('avatar') | ||
->label(__('filament-breezy::default.fields.avatar')) | ||
->avatar() | ||
->collection('avatars') | ||
->conversion('large'); | ||
} | ||
|
||
$groupFields[] = Group::make() | ||
->columnSpan(2) | ||
->columns(2) | ||
->schema([ | ||
TextInput::make('first_name'), | ||
TextInput::make('last_name'), | ||
|
||
$this->getEmailComponent() | ||
->columnSpanFull(), | ||
]); | ||
|
||
return $groupFields; | ||
} | ||
} |
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.