init
This commit is contained in:
236 files changed
+24692
No files matched your search
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Collection extends LocalizedContent
|
||||
{
|
||||
public const COVER_DIRECTORY = 'collection-covers';
|
||||
|
||||
public function designs(): HasMany
|
||||
{
|
||||
return $this->hasMany(Design::class);
|
||||
}
|
||||
|
||||
public function coverUrl(bool $preview = false): ?string
|
||||
{
|
||||
if (! $this->cover) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! str_starts_with($this->cover, self::COVER_DIRECTORY.'/')) {
|
||||
return asset($this->cover);
|
||||
}
|
||||
|
||||
return route($preview ? 'studio.collection-cover' : 'collection.cover', [
|
||||
'id' => $this->id,
|
||||
'file' => basename($this->cover),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Design extends LocalizedContent
|
||||
{
|
||||
protected function casts(): array
|
||||
{
|
||||
return [...parent::casts(), 'illustrative' => 'boolean'];
|
||||
}
|
||||
|
||||
public function collection(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Collection::class);
|
||||
}
|
||||
|
||||
public function dailyViews(): HasMany
|
||||
{
|
||||
return $this->hasMany(DesignDailyView::class);
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function visible(Builder $query): void
|
||||
{
|
||||
$query->published()->whereHas('collection', fn (Builder $collection) => $collection->published())
|
||||
->whereNotNull('artwork_path');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DesignDailyView extends Model
|
||||
{
|
||||
public const TIMEZONE = 'Asia/Tehran';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public static function today(): CarbonImmutable
|
||||
{
|
||||
return now(self::TIMEZONE)->toImmutable()->startOfDay();
|
||||
}
|
||||
|
||||
public static function recordView(int $designId, string $date): void
|
||||
{
|
||||
static::query()->upsert([
|
||||
['design_id' => $designId, 'viewed_on' => $date, 'views' => 1],
|
||||
], ['design_id', 'viewed_on'], ['views' => DB::raw('design_daily_views.views + 1')]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class GarmentTemplate extends Model
|
||||
{
|
||||
public const PHOTO_DIRECTORY = 'garment-photos';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'placements' => 'array',
|
||||
'illustrative' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function photoUrl(): string
|
||||
{
|
||||
if (! str_starts_with($this->photo, self::PHOTO_DIRECTORY.'/')) {
|
||||
return asset($this->photo);
|
||||
}
|
||||
|
||||
return route('garment.photo', ['id' => $this->id, 'file' => basename($this->photo)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
abstract class LocalizedContent extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['published_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function text(string $field, ?string $locale = null): string
|
||||
{
|
||||
return $this->getAttribute($field.'_'.($locale ?? app()->getLocale()));
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function published(Builder $query): void
|
||||
{
|
||||
$query->where('published_at', '<=', now());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
public const STUDIO_PUBLIC_INFORMATION = 'studio.public_information';
|
||||
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $fillable = ['key', 'value'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['value' => 'json'];
|
||||
}
|
||||
|
||||
public static function read(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$setting = static::query()->find($key);
|
||||
|
||||
return $setting === null ? $default : $setting->value;
|
||||
}
|
||||
|
||||
public static function write(string $key, mixed $value): void
|
||||
{
|
||||
static::query()->updateOrCreate(['key' => $key], ['value' => $value]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return (bool) $this->is_staff;
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user