Moved from "app/src" to "app/application".

Otherwise phpstorm doesn't understand the paths correctly. He thinks that this is not a complete application, but a package. And when creating a class, the namespace indicates “app” with a small letter, but should be “App”.
This commit is contained in:
2024-04-11 19:52:37 +05:00
parent e41f63f94f
commit b7d0a2453e
314 changed files with 5 additions and 5 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php declare(strict_types=1);
namespace App\Models;
use App\Models\Traits\StorageTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Contracts\Models\Storage as StorageContract;
final class Project extends Model implements StorageContract
{
use HasFactory, SoftDeletes, StorageTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'code',
'http_host',
'is_public'
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'is_public' => 'boolean',
];
}
public function roles(): MorphMany
{
return $this->morphMany(Role::class, 'morph');
}
public function languages(): HasMany
{
return $this->hasMany(ProjectLanguage::class);
}
}
@@ -0,0 +1,50 @@
<?php declare(strict_types=1);
namespace App\Models;
use App\Models\Scopes\SortScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
#[ScopedBy([SortScope::class])]
final class ProjectLanguage extends Model
{
use HasFactory, SoftDeletes;
/**
* The model's default values for attributes.
*
* @var array
*/
protected $attributes = [
'is_default' => false,
'sort' => 100,
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'code',
'is_default',
'sort',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'is_default' => 'boolean',
'sort' => 'integer',
];
}
}
+75
View File
@@ -0,0 +1,75 @@
<?php declare(strict_types=1);
namespace App\Models;
use App\Enums\SystemRole as SystemRoleEnum;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\hasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
final class Role extends Model
{
use HasFactory, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'code',
];
public function scopeLatest(Builder $query): Builder
{
return $query->orderBy('id', 'desc');
}
public function scopeAlphavit(Builder $query): Builder
{
return $query->orderBy('name', 'asc');
}
protected function nameWithMorph(): Attribute
{
return Attribute::make(
get: function () {
$name = $this->name;
if ($this->morph_type) {
$name .= ' (' . __('admin-sections.Projects') . ': ' . $this->morph?->name . ')';
}
return $name;
},
)->shouldCache();
}
public function morph(): MorphTo
{
return $this->morphTo('morph');
}
public function permissions(): hasMany
{
return $this->hasMany(RolePermission::class, 'role_id', 'id');
}
protected function isRemove(): Attribute
{
return Attribute::make(
get: fn ($dontRemove) => ( SystemRoleEnum::tryFrom($this->code) === null ),
)->shouldCache();
}
protected function isAdmin(): Attribute
{
return Attribute::make(
get: fn () => ( \is_null($this->morphable_type) && \is_null($this->morphable_id) && $this->code === SystemRoleEnum::Admin->value ),
)->shouldCache();
}
}
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
namespace App\Models;
use App\Enums\Permission;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
final class RolePermission extends Model
{
use HasFactory;
protected $table = 'role_permission';
public function getPermissionTitleAttribute(): string
{
$pemissions = Permission::toArrayList();
return $pemissions[$this->permission] ?? '';
}
}
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
final class SortScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void
{
$builder->orderBy('sort', 'asc');
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php declare(strict_types=1);
namespace App\Models;
use App\Enums\StorageType;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage as StorageSupport;
class Storage extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'storage';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'data',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'data' => 'array',
'type' => StorageType::class,
];
}
protected function dataImages(): Attribute
{
return Attribute::make(
get: fn () => $this->data['images'] ?? [],
);
}
protected function url(): Attribute
{
return Attribute::make(
get: function () {
if (\is_null($this->file)) {
return '';
}
return StorageSupport::disk(config('storage.disk'))->url($this->file) . '?time=' . $this->updated_at->getTimestamp();
},
);
}
protected function path(): Attribute
{
return Attribute::make(
get: function () {
if (\is_null($this->file)) {
return '';
}
return StorageSupport::disk(config('storage.disk'))->path($this->file);
},
);
}
}
@@ -0,0 +1,26 @@
<?php declare(strict_types=1);
namespace App\Models\Traits;
use App\Enums\StorageType;
use App\Models\Storage as StorageModel;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Relations\MorphMany;
trait StorageTrait
{
public function storage(): MorphMany
{
return $this->morphMany(StorageModel::class, 'morph');
}
public function getStorageOne(StorageType $type): ?StorageModel
{
return $this->storage->firstWhere('type', $type);
}
public function getStorageMany(StorageType $type): Collection
{
return $this->storage->where('type', $type);
}
}
+87
View File
@@ -0,0 +1,87 @@
<?php declare(strict_types=1);
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Enums\Lang;
use App\Enums\SystemRole;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
final class User extends Authenticatable
{
use HasFactory, Notifiable, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'nickname',
'timezone',
'lang',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'lang' => Lang::class,
];
}
public function roles(): belongsToMany
{
return $this->belongsToMany(Role::class);
}
public function hasPermission(string $permission): bool
{
return $this->permissions->search($permission) !== false;
}
protected function isAdmin(): Attribute
{
return Attribute::make(
get: fn () => $this->roles
->where('code', SystemRole::Admin->value)
->whereNull('morphable_type')
->whereNull('morphable_id')
->isNotEmpty(),
)->shouldCache();
}
protected function permissions(): Attribute
{
return Attribute::make(
get: function () {
$roles = $this->roles->modelKeys();
return RolePermission::query()->whereIn('role_id', $roles)->select('permission')->pluck('permission');
},
)->shouldCache();
}
}