restore composer.json, add mysqli extension

This commit is contained in:
2026-04-15 17:02:52 +05:00
commit 77cf56a348
4317 changed files with 1397107 additions and 0 deletions

102
app/Models/Address.php Executable file
View File

@@ -0,0 +1,102 @@
<?php
namespace App\Models;
use App\Models\User;
use App\Models\City;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\Activitylog\Traits\LogsActivity;
/**
* Class Address
* @property int $user_id
* @property int $city_id
* @property string|null $address
* @property string|null $home
* @property string|null $landmark
*
* @property-read User $user
* @property-read City $city
*
* @method getCity(): string
* @method getLandmark(): string
* @method getHome(): string
* @method getHomeAddress(): string
* @method getShortAddress(): string
* @method getFullAddress(): string
* @method getAddress(): string
*/
class Address extends Model
{
use LogsActivity, LogOptionsTrait, SoftDeletes;
protected $guarded = ['id'];
protected $casts = [
'user_id' => 'integer',
'city_id' => 'integer',
'address' => 'string',
'home' => 'string',
'landmark' => 'string',
];
protected static $logName = 'addresses';
protected static $recordEvents = ['deleted', 'updated'];
protected static $logOnlyDirty = true;
protected static $logAttributes = [
'user_id',
'city_id',
'address',
'home',
'landmark'
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function city(): BelongsTo
{
return $this->belongsTo(City::class, 'city_id', 'id');
}
public function getCity(): string
{
return (string) $this->city->getName();
}
public function getFullAddress(): string|null
{
return $this->getCity() . ', ' . $this->address . ', ' . $this->home . ', ' . $this->landmark;
}
public function getShortAddress(): string|null
{
return $this->getCity() . ', ' . $this->address;
}
public function getHomeAddress(): string|null
{
return $this->home . ', ' . $this->landmark;
}
public function getAddress(): string|null
{
return $this->address;
}
public function getHome(): string|null
{
return $this->home;
}
public function getLandmark(): string|null
{
return $this->landmark;
}
}

34
app/Models/Billing.php Executable file
View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
class Billing extends Model
{
use LogsActivity, LogOptionsTrait;
protected $guarded = ['id'];
protected $casts = [
'order_id' => 'integer',
'amount' => 'integer',
'transaction_id' => 'string'
];
protected static $logName = 'billings';
protected static $recordEvents = ['deleted', 'updated'];
protected static $logOnlyDirty = true;
protected static $logAttributes = [
'order_id', 'amount', 'transaction_id', 'status', 'payment_system'
];
protected static $submitEmptyLogs = false;
public function order()
{
return $this->belongsTo(Order::class, 'order_id', 'id');
}
}

80
app/Models/Branch.php Executable file
View File

@@ -0,0 +1,80 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\App;
/**
* Class Branch
* @property array|null $name
* @property array|null $address
* @property array|null $schedule
* @property string|null $map
* @property string|null $phone
* @property array|null $orientation
* @mixin Model
*/
class Branch extends Model
{
use SoftDeletes;
protected $table = 'branches';
protected $fillable = [
'name', 'address', 'schedule', 'map', 'phone', 'orientation'
];
protected $casts = [
'name' => 'array',
'address' => 'array',
'schedule' => 'array',
'map' => 'array',
'orientation' => 'array',
];
protected $hidden = [
'created_at', 'updated_at', 'deleted_at'
];
/**
* @return mixed
*/
public function getName()
{
return $this->name[App::getLocale()] ?? null;
}
/**
* @return mixed
*/
public function getAddress()
{
return $this->address[App::getLocale()] ?? null;
}
/**
* @return mixed
*/
public function getSchedule()
{
return $this->schedule[App::getLocale()] ?? null;
}
public function getLat(): string
{
return (string) $this->map['lat'];
}
public function getLong(): string
{
return (string) $this->map['long'];
}
public function getPhone(): string
{
return (string) $this->phone;
}
}

82
app/Models/Brand.php Executable file
View File

@@ -0,0 +1,82 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Support\Facades\App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Traits\LogsActivity;
/**
* Class Brend
* @property string|null $name
* @property string|null $image
* @property integer|null $id
* @mixin Model
*/
class Brand extends Model
{
use LogsActivity, LogOptionsTrait;
/**
* @var array
*/
protected $fillable = [
'name',
'image',
'slug',
"position",
];
/**
* @var array
*/
protected $casts = [
'name' => 'array',
'image' => 'string'
];
protected static $logName = 'brand';
protected static $logAttributes = ['name'];
protected static $submitEmptyLogs = false;
protected static $logOnlyDirty = true;
/**
* @return int
*/
public function getID(): int
{
return (int) $this->id;
}
public function getName()
{
return $this->name[App::getLocale()] ?? null;
}
/**
* @return string
*/
public function getImage(): string
{
if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image,
Date::now()->addMinutes(5)
);
};
return (string) '/' . $this->image;
}
return (string) 'images/no_brend.png';
}
public function categories()
{
return $this->belongsToMany(Category::class, 'categories_brands');
}
}

71
app/Models/Cart.php Executable file
View File

@@ -0,0 +1,71 @@
<?php
namespace App\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cookie;
/**
* Class Cart
* @property integer|null $user_id
* @property integer $product_id
* @property integer $count
* @property string|null $size
* @property string|null $token
* @mixin Model
*/
class Cart extends Model
{
/**
* @var array
*/
protected $guarded = ['id'];
/**
* @var array
*/
protected $casts = [
'user_id' => 'integer',
'token' => 'string',
'product_id' => 'integer',
'count' => 'integer',
'size' => 'string'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function product()
{
return $this->belongsTo(Product::class);//->where('parent_id', null);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* @param $query
* @param $token
* @return mixed
*/
public function scopeFindByToken($query, $token)
{
return $query->where('token', $token);
}
/**
* @param $query
* @param $user_id
* @return mixed
*/
public function scopeFindByUser($query, $user_id)
{
return $query->where('user_id', $user_id);
}
}

247
app/Models/Category.php Executable file
View File

@@ -0,0 +1,247 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\Activitylog\Traits\LogsActivity;
/**
* @package App\Models
* @property int $id
* @property array $name
* @property string|null $image
* @property string $slug
* @property int|null $parent_id
* @property int $position
* @property bool $popular
* @property bool $published
* @property array $title_seo
* @property array $keywords
* @property bool $is_filter_power
* @property array $descriptions
*
* @property-read Brand $brands
*/
class Category extends Model
{
use LogsActivity, LogOptionsTrait;
/**
* @var array
*/
protected $guarded = ['id'];
/**
* @var array
*/
protected $casts = [
'name' => 'array',
'parent_id' => 'integer',
'position' => 'integer',
'slug' => 'string',
'image' => 'string',
'popular' => 'boolean',
'published' => 'boolean',
'keywords' => 'array',
'descriptions' => 'array',
'title_seo' => 'array',
'is_filter_power' => 'boolean'
];
protected $hidden = [
'created_at',
'updated_at'
];
protected static $logName = 'categories';
protected static $logOnlyDirty = true;
protected static $ignoreChangedAttributes = ['position'];
protected static $logAttributes = ['name', 'parent_id', 'published', 'title_seo'];
protected static $submitEmptyLogs = false;
/**
* @return int
*/
public function getID(): int
{
return (int) $this->id;
}
/**
* @return string
*/
public function getRouteKeyName()
{
return 'slug';
}
/**
* @return string|null
*/
public function getLowerName()
{
return Str::lower($this->name[App::getLocale()]) ?? null;
}
/**
* @return mixed
*/
public function getName()
{
if (App::getLocale() == 'en') {
return $this->name['ru'];
}
return $this->name[App::getLocale()] ?? null;
}
/**
* @return string
*/
public function getDescriptions(): string
{
if (App::isLocale('ru')) {
if (!empty($this->descriptions['ru'])) {
return (string) $this->descriptions['ru'];
}
}
if (!empty($this->descriptions['uz'])) {
return (string) $this->descriptions['uz'];
}
return (string) '';
}
/**
* @return string
*/
public function getKeywords()
{
if (App::isLocale('ru')) {
if (!empty($this->keywords['ru'])) {
return $this->keywords['ru'];
}
}
if (!empty($this->keywords['uz'])) {
return $this->keywords['uz'];
}
return '';
}
public function getImage(): string
{
if (!in_array($this->image, ['null', null])) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image,
Date::now()->addMinutes(5)
);
}
return (string) $this->image;
}
return (string) 'images/nophoto.jpg';
}
public function getParentId(): int
{
return $this->parent_id;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent()
{
return $this->belongsTo(self::class, 'parent_id', 'id')->where('published', true);
}
public function parents()
{
return $this->hasMany(self::class, 'parent_id', 'id')->where('published', true)->orderBy('position', 'asc');
}
public function children()
{
return $this->hasMany(self::class, 'parent_id', 'id')->orderBy('position', 'asc');
}
/**
* @return string
*/
public function getTitleSeo(): string
{
if (App::isLocale('ru')) {
if (!empty($this->title_seo['ru'])) {
return (string) $this->title_seo['ru'];
}
}
if (!empty($this->title_seo['uz'])) {
return (string) $this->title_seo['ru'];
}
return $this->getName();
}
/**
* @return int
*/
public function position(): int
{
return (int) $this->position;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function brands()
{
return $this->belongsToMany(Brand::class, 'categories_brands');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function products()
{
return $this->belongsToMany(Product::class, 'categories_products');
}
/**
* @param $query
* @param $slug
* @return mixed
*/
public function scopeFindBySlug($query, $slug)
{
return $query->where('slug', $slug);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function characteristics()
{
return $this->hasMany(Characteristic::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function filter()
{
return $this->belongsToMany(Characteristic::class, 'characteristics_categories');
}
}

55
app/Models/Characteristic.php Executable file
View File

@@ -0,0 +1,55 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Characteristic extends Model
{
/**
* @var array
*/
protected $guarded = ['id'];
/**
* @var array
*/
protected $casts = [
'category_id' => 'integer',
'name' => 'array',
'type' => 'string',
'options' => 'array',
'filter' => 'boolean'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function category()
{
return $this->belongsTo(Category::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function product()
{
return $this->belongsToMany(Product::class,'characteristics_products')->withPivot('value');
}
public function values()
{
return $this->belongsToMany(Product::class,'characteristics_products')
->withPivot('value')
->select('product_id', 'value');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function filter()
{
return $this->belongsToMany(Category::class, 'characteristics_categories');
}
}

36
app/Models/City.php Executable file
View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
class City extends Model
{
use LogsActivity, LogOptionsTrait;
protected $table = 'cities';
protected $guarded = ['id'];
protected $casts = [
'name' => 'array',
'region_id' => 'integer'
];
protected static $logName = 'cities';
protected static $logOnlyDirty = true;
protected static $logAttributes = ['name', 'region_id'];
protected static $submitEmptyLogs = false;
public function region()
{
return $this->belongsTo(Region::class, 'region_id', 'id');
}
public function getName()
{
return (string) $this->name['ru'] ?? null;
}
}

39
app/Models/Color.php Executable file
View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
/**
* Class Color
* @property string|null $name
* @property string|null $color
* @mixin
*/
class Color extends Model
{
protected $table = 'colors';
protected $fillable = [
'name', 'color'
];
protected $casts = [
'name' => 'array',
];
protected $hidden = [
'created_at', 'updated_at'
];
public function getName()
{
return (string) $this->name[App::getLocale()] ?? null;
}
public function getColor(): string
{
return (string) $this->color;
}
}

51
app/Models/Comment.php Executable file
View File

@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $guarded = ['id'];
protected $fillable = [
'first_name',
'body',
'user_id',
'product_id',
'star',
'publish'
];
/**
* @var array
*/
protected $casts = [
'body' => 'string',
'first_name' => 'string',
'created_at' => 'datetime:H:i d.m.Y',
'publish' => 'boolean',
'star' => 'integer'
];
protected $hidden = [
'update_at', 'user_id', 'product_id'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function product()
{
return $this->belongsTo(Product::class)->withTrashed();
}
}

18
app/Models/CommentBank.php Executable file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CommentBank extends Model
{
protected $table = 'comments_bank';
protected $guarded = ['id'];
protected $casts = [
'comment' => 'string',
'order_id' => 'integer'
];
}

43
app/Models/Company.php Executable file
View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @package App\Models
* @property int $id
* @property string $company_name
* @property string $inn
* @property string $bank_name
* @property string $mfo
* @property string $oked
* @property array $address
* @property string $payment_account
* @property string $phone
* @property string $director_full_name
*/
class Company extends Model
{
use HasFactory;
protected $fillable = [
'company_name',
'inn',
'bank_name',
'mfo',
'oked',
'address',
'director_full_name',
'payment_account',
'phone',
];
protected $casts = [
'address' => 'array',
"company_name" => "array",
"director_full_name" => "array",
"bank_name" => "array",
];
}

117
app/Models/Compilation.php Executable file
View File

@@ -0,0 +1,117 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Class Compilation
* @property string|null $title
* @property integer|null $position
* @property integer|null $category_id
* @property boolean|null $published
* @mixin Model
*/
class Compilation extends Model
{
/**
* @var array
*/
protected $fillable = [
'title',
'position',
'published',
'category_id'
];
/**
* @var array
*/
protected $casts = [
'title' => 'array',
'position' => 'integer',
'published' => 'boolean',
'category_id' => 'integer'
];
/**
* @return string
*/
public function getTitle(): string
{
return $this->title['ru'];
}
/**
* @return bool
*/
public function isAviable(): bool
{
return $this->published;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function products()
{
return $this->belongsToMany(Product::class, 'compilation_products')->where('published', true)->limit(10);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function category()
{
return $this->belongsTo(Category::class);
}
/**
* @param $query
* @return mixed
*/
public function scopePublished($query)
{
return $query->where('published', true);
}
/**
* @param $query
* @param $id
* @return mixed
*/
public function scopeCategory($query, $id)
{
return $query->where('category_id', $id);
}
/**
* @param $query
* @return mixed
*/
public function scopeNewProducts($query)
{
return $query->where('id', 1);
}
/**
* @param $query
* @return mixed
*/
public function scopePopularProducts($query)
{
return $query->where('id', 3);
}
/**
* @param $query
* @return mixed
*/
public function scopeLiderProducts($query)
{
return $query->where('id', 2);
}
}

44
app/Models/ContractTemplate.php Executable file
View File

@@ -0,0 +1,44 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property integer $id
* @property string $path
* @property string $lang
* @property string $type
*
* @method string full_path()
*/
class ContractTemplate extends Model
{
use HasFactory;
protected $fillable = [
'path',
'lang',
"company",
'type',
];
public function full_path(): string
{
if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->path,
Date::now()->addMinutes(5)
);
}
return '/' . $this->path;
}
return asset('storage/' . $this->path);
}
}

24
app/Models/Currency.php Executable file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Currency extends Model
{
protected $fillable = [
'dollar',
'euro',
'sum'
];
protected $casts = [
'dollar' => 'integer',
'euro' => 'integer',
];
public static function getCurrency()
{
return self::latest()->first();
}
}

21
app/Models/DeliveryPrice.php Executable file
View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @package App\Models
* @property int $id
* @property int $region_id
* @property int $power_id
* @property float $price
*/
class DeliveryPrice extends Model
{
use HasFactory, SoftDeletes;
protected $guarded = ['id'];
}

80
app/Models/Favorite.php Executable file
View File

@@ -0,0 +1,80 @@
<?php
namespace App\Models;
use App\Models\User;
use App\Models\Product;
use Illuminate\Database\Eloquent\Model;
/**
* @package App\Models
* @property int|null $user_id
* @property string|null $token
* @property int $product_id
*
* @property-read User $user
* @property-read Product $product
*/
class Favorite extends Model
{
protected $table = 'products_users';
public $timestamps = false;
public $incrementing = false;
/**
* @var array
*/
protected $fillable = [
'user_id', 'product_id', 'token'
];
/**
* @var array
*/
protected $casts = [
'user_id' => 'integer',
'product_id' => 'integer',
'token' => 'string'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function product()
{
return $this->belongsTo(Product::class);
}
/**
* @param $query
* @param $token
* @return mixed
*/
public function scopeFindByToken($query, $token)
{
return $query->where('token', $token);
}
/**
* @param $query
* @return mixed
*/
public function scopeFindByList($query)
{
if (auth()->check()) {
return $query->where('user_id', auth()->user()->id);
}
return $query->where('token', request()->cookie('token'));
}
}

24
app/Models/Feedback.php Executable file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Feedback extends Model
{
protected $fillable = [
'name',
'phone',
'message',
'viewed'
];
protected $casts = [
'viewed' => 'boolean'
];
public function setPhoneAttribute($phone)
{
return $this->attributes['phone'] = str_replace(['+', '-', '(', ')', ' '], '', $phone);
}
}

85
app/Models/File.php Executable file
View File

@@ -0,0 +1,85 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* Class File
* @property string|null $name
* @property string|null $path
* @property string|null $path_thumb
* @property float|null $size
* @mixin Model
*/
class File extends Model
{
/**
* @var array
*/
protected $fillable = [
'name', 'path', 'path_thumb', 'size'
];
/**
* @var array
*/
protected $casts = [
'name' => 'string',
'path' => 'string',
'path_thumb' => 'string',
'size' => 'float'
];
/**
* @return string
*/
public function getName(): string
{
return (string) $this->name;
}
/**
* @return string|null
*/
public function getPath()
{
if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->path, Date::now()->addMinutes(5)
);
}
return (string) $this->path;
}
return null;
}
/**
* @return string|null
*/
public function getPathThumb()
{
if (!empty($this->path_thumb)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->path_thumb, Date::now()->addMinutes(5)
);
}
return (string) $this->path_thumb;
}
return null;
}
/**
* @return float
*/
public function getSize(): float
{
return (float) $this->size;
}
}

39
app/Models/Firebase.php Executable file
View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
/**
* @package App\Models
* @property int $id
* @property int|null $user_id
* @property string $token
* @property string $device_id
* @property string $device_name
* @property string $device_type
*
* @property-read User $user
*/
class Firebase extends Model
{
public $timestamps = false;
protected $fillable = [
'user_id', 'token', 'device_id', 'device_name', 'device_type'
];
protected $casts = [
'user_id' => 'integer',
'token' => 'string'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
}

35
app/Models/Measurement.php Executable file
View File

@@ -0,0 +1,35 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
/**
* @package App\Models
* @property int $id
* @property array $name
*
*/
class Measurement extends Model
{
use HasFactory;
protected $fillable = [
'name',
];
protected $casts = [
'name' => 'array',
];
public function getName(): string | null
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
}

25
app/Models/Notification.php Executable file
View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* package App\Models
* @property int $id
* @property string $title
* @property string $body
* @property string $language // [uz, ru], ru is default
*/
class Notification extends Model
{
protected $fillable = [
'title', 'body', 'language'
];
protected $casts = [
'title' => 'string',
'body' => 'string',
'language' => 'string',
];
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class NotificationAvailable extends Model
{
/**
* @var array
*/
protected $guarded = ['id'];
/**
* @var array
*/
protected $casts = [
'phone' => 'integer',
'product_id' => 'integer'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function product()
{
return $this->belongsTo(Product::class);
}
}

200
app/Models/Order.php Executable file
View File

@@ -0,0 +1,200 @@
<?php
namespace App\Models;
use App\Models\User;
use App\Models\Address;
use App\Models\OrderProducts;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\Traits\LogsActivity;
/**
* @package App\Models
* @property integer $id
* @property integer $user_id
* @property integer|null $branch_id
* @property string|null $full_name
* @property string|null $phone
* @property string|null $legal_id
* @property string|null $address_id
* @property boolean $with_installation
* @property string $client_type // physical, legal
* @property string $payment_type // cash, bank, click, payme
* @property boolean $with_didox
* @property string $delivery_type // pickup, delivery
* @property string|null $shipment_date
* @property string|null $accepted_at
* @property null $currency
* @property string $status // processing, collected, waiting_buyer, in_way, closed, cancelled, replacement, completed
* @property string $payment_status // waiting, cancelled, payed, cash, review
* @property boolean $archived
* @property int $price_products
* @property int $price_delivery
* @property int $price_total
* @property int $price_master
*
* @property-read User|BelongsTo $user
* @property-read Address|HasOne $address
* @property-read Collection|OrdersComment[]|HasMany $comments
* @property-read UserLegalInfo|BelongsTo $legalInfo
* @property-read Collection|OrderProducts[]|HasMany $products
* @property-read Branch|BelongsTo $branch
* @property-read Status|BelongsTo $getStatus
* @property-read Status|BelongsTo $getPaymentStatus
*/
class Order extends Model
{
use LogsActivity, LogOptionsTrait, SoftDeletes;
protected $guarded = ['id'];
protected $casts = [
'user_id' => 'integer',
'branch_id' => 'integer',
'with_installation' => 'boolean',
'with_didox' => 'boolean',
'shipment_date' => 'datetime',
'accepted_at' => 'datetime',
'address_id' => 'integer',
'archived' => 'boolean',
];
protected static $logName = 'orders';
protected static $logOnlyDirty = true;
protected static $logAttributes = [
'full_name',
'phone',
'legal_id',
'address_id',
'with_installation',
'client_type',
'payment_type',
'with_didox',
'delivery_type',
'shipment_date',
'accepted_at',
'currency',
'status',
'payment_status',
'archived',
];
protected static $submitEmptyLogs = false;
public static function statuses()
{
return [
'processing',
'collected',
'waiting_buyer',
'in_way',
'closed',
'cancelled',
'replacement',
'completed'
];
}
public static function paymentStatuses()
{
return [
'waiting',
'cancelled',
'payed',
'cash',
'review'
];
}
public static function paymentTypes()
{
return [
'bank',
'cash',
'click',
'payme',
];
}
public static function clientTypes()
{
return [
'physical',
'legal',
];
}
public static function deliveryTypes()
{
return [
'delivery',
'pickup',
];
}
public function getStatus()
{
return $this->belongsTo(Status::class, 'status', 'slug');
}
public function contracts(): HasMany
{
return $this->hasMany(OrderContract::class, 'order_id', 'id');
}
public function getCurrency(): BelongsTo
{
return $this->belongsTo(Currency::class, 'currency', 'id');
}
public function getPaymentStatus()
{
return $this->belongsTo(Status::class, 'payment_status', 'slug');
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function address(): BelongsTo
{
return $this->belongsTo(Address::class, 'address_id', 'id');
}
public function comments(): HasMany
{
return $this->hasMany(OrdersComment::class, 'order_id', 'id');
}
public function legalInfo(): BelongsTo
{
return $this->belongsTo(UserLegalInfo::class, 'legal_id', 'id');
}
public function products(): HasMany
{
return $this->hasMany(OrderProducts::class, 'order_id', 'id');
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class);
}
public function getProductsPrice()
{
return $this->products->sum('total_price');
}
public function billing()
{
return $this->hasOne(Billing::class);
}
}

32
app/Models/OrderAddress.php Executable file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @package App\Models
* @property integer $id
* @property integer $order_id
* @property integer $city_id
* @property string $home
* @property string $landmark
*
* @property-read Order $order
* @property-read City $city
*/
class OrderAddress extends Model
{
protected $guarded = ['id'];
public function city(): BelongsTo
{
return $this->belongsTo(City::class);
}
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
}

66
app/Models/OrderContract.php Executable file
View File

@@ -0,0 +1,66 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property integer $id
* @property integer $order_id
* @property string $type
* @property string $path
*
* @property-read Order|BelongsTo $order
*
* @mother isContract(): bool
* @mother isMasterContract(): bool
*/
class OrderContract extends Model
{
use HasFactory;
const TYPE_CONTRACT = 'contract';
const TYPE_MASTER = 'master_contract';
protected $guarded = ['id'];
protected $casts = [
'order_id' => 'integer',
];
public function getPath()
{
if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->path,
Date::now()->addMinutes(5)
);
}
return env('APP_URL') . '/storage/' . $this->path;
}
return null;
}
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
public function isContract(): bool
{
return $this->type === self::TYPE_CONTRACT;
}
public function isMasterContract(): bool
{
return $this->type === self::TYPE_MASTER;
}
}

66
app/Models/OrderProducts.php Executable file
View File

@@ -0,0 +1,66 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Order;
use App\Models\Product;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @package App\Models
* @property integer $id
* @property integer $order_id
* @property integer $product_id
* @property integer $count
* @property $price
* @property integer $discount
*
* @property-read Order $order
* @property-read Product $product
*
* @property-read float $total_price
* @property-read float $final_price
*/
class OrderProducts extends Model
{
protected $guarded = ['id'];
public $timestamps = false;
protected $casts = [
'order_id' => 'integer',
'product_id' => 'integer',
'count' => 'integer',
];
public function order(): BelongsTo
{
return $this->belongsTo(Order::class)->withTrashed();
}
public function getCount()
{
return $this->count;
}
public function product(): BelongsTo
{
return $this->belongsTo(Product::class)->withTrashed();
}
public function getFinalPriceAttribute(): float
{
if (!empty($this->discount)) {
return $this->discount;
} else {
return $this->price;
}
}
public function getTotalPriceAttribute(): float
{
$price = $this->discount ?? $this->price;
return $price * $this->count;
}
}

25
app/Models/OrdersComment.php Executable file
View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @package App\Models
* @property int $id
* @property int $order_id
* @property int $user_id
* @property string $comment
* @property string $type
*/
class OrdersComment extends Model
{
protected $guarded = ['id'];
protected $table = 'orders_comments';
public function user()
{
return $this->belongsTo(Staff::class, 'user_id', 'id');
}
}

55
app/Models/Page.php Executable file
View File

@@ -0,0 +1,55 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Spatie\Activitylog\Traits\LogsActivity;
class Page extends Model
{
use LogsActivity, LogOptionsTrait;
protected $guarded = ['id'];
protected $casts = [
'name' => 'array',
'body' => 'array',
'keywords' => 'array',
'descriptions' => 'array',
];
protected static $logName = 'pages';
protected static $logOnlyDirty = true;
protected static $logAttributes = ['name', 'body'];
protected static $submitEmptyLogs = false;
public function getName()
{
return (string) $this->name[app()->getLocale()] ?? null;
}
public function getBody()
{
return (string) $this->body[app()->getLocale()] ?? null;
}
public function getDescriptions()
{
if (App::isLocale('ru')) {
return $this->descriptions['ru'];
}
return $this->descriptions['uz'];
}
public function getKeywords()
{
if (App::isLocale('ru')) {
return $this->keywords['ru'];
}
return $this->keywords['uz'];
}
}

85
app/Models/Partner.php Executable file
View File

@@ -0,0 +1,85 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property int $id
* @property array $name
* @property array $description
* @property string $video_url
* @property string $image
* @property string $status
* @property bool $is_price
*
* @property Region[] $regions
* @property Status $getStatus
*
*/
class Partner extends Model
{
protected $fillable = [
'name',
'description',
'video_url',
'image',
'status',
"position",
'is_price',
];
protected $casts = [
'is_price' => 'boolean',
'description' => 'array',
'name' => 'array',
];
//? Statuses: new, soon, published
public function getStatus()
{
return $this->belongsTo(Status::class, 'status', 'slug');
}
/**
* @return string
*/
public function getImage(): string
{
if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image,
Date::now()->addMinutes(5)
);
}
return (string) $this->image;
}
return (string) 'images/no_brend.png';
}
public function getName(): string
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
public function getDescription(): string
{
if (App::isLocale('ru')) {
return (string) $this->description['ru'];
}
return (string) $this->description['uz'];
}
}

59
app/Models/PartnerRequest.php Executable file
View File

@@ -0,0 +1,59 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @package App\Models
* @property int $id
* @property int $partner_id
* @property int $city_id
* @property int $user_id
* @property $price
* @property string|null $comment
* @property int $phone
* @property string $status // pending, accepted, closed, rejected
* @property string $full_name
*
* @property Partner $partner
* @property City $city
* @property Status $getStatus
*/
class PartnerRequest extends Model
{
use HasFactory;
protected $fillable = [
'partner_id',
'city_id',
'user_id',
'price',
'comment',
'phone',
'full_name',
'status'
];
public function getStatus(): BelongsTo
{
return $this->belongsTo(Status::class, 'status', 'slug');
}
public function partner(): BelongsTo
{
return $this->belongsTo(Partner::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function city(): BelongsTo
{
return $this->belongsTo(City::class);
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property int $id
* @property int $payment_system_id
* @property array $title
* @property string $logo
* @property string $slug
* @property array $description
*
* @property PaymentSystemModel $paymentSystem
*
* @method getLogo(): string
*/
class PaymentSystemItem extends Model
{
use HasFactory;
protected $fillable = [
'payment_system_id',
'title',
'logo',
'slug',
'description'
];
protected $casts = [
'title' => 'array',
'description' => 'array'
];
protected $table = 'payment_system_items';
public function paymentSystem(): BelongsTo
{
return $this->belongsTo(PaymentSystemModel::class, 'payment_system_id', 'id');
}
public function getTitle(): string
{
if (App::isLocale('ru')) {
return (string) $this->title['ru'];
}
return (string) $this->title['uz'];
}
public function getDescription(): string
{
if ($this->description == null) {
return '';
}
if (App::isLocale('ru')) {
return (string) $this->description['ru'];
}
return (string) $this->description['uz'];
}
public function getLogo(): string
{
if (!empty($this->logo)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->logo,
Date::now()->addMinutes(5)
);
}
return env('APP_URL').'/'.$this->logo;
}
return '/images/nophoto.jpg';
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\App;
/**
* @package App\Models
* @property int $id
* @property array $title
* @property string $slug
*
* @property PaymentSystemItem[]|HasMany $items
*
* @method getTitle(): string
*/
class PaymentSystemModel extends Model
{
use HasFactory;
protected $fillable = ['title', 'slug'];
protected $casts = [
'title' => 'array',
];
protected $table = 'payment_system_models';
public function items(): HasMany
{
return $this->hasMany(PaymentSystemItem::class, 'payment_system_id', 'id');
}
public function getTitle(): string
{
if (App::isLocale('ru')) {
return (string) $this->title['ru'];
}
return (string) $this->title['uz'];
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @package App\Models
* @property int $id
* @property string $tokenable_type
* @property int $tokenable_id
* @property string $name
* @property string $token
* @property array $abilities
* @property \Carbon\Carbon $last_used_at
* @property \Carbon\Carbon $expires_at
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*/
class PersonalAccessToken extends Model
{
protected $table = 'personal_access_tokens';
protected $casts = [
'abilities' => 'array',
'last_used_at' => 'datetime',
'expires_at' => 'datetime',
];
protected $fillable = [
'tokenable_type',
'tokenable_id',
'name',
'token',
'abilities',
'last_used_at',
'expires_at',
];
}

104
app/Models/Post.php Executable file
View File

@@ -0,0 +1,104 @@
<?php
namespace App\Models;
use App\Helpers\Month;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
/**
* @package App\Models
* @property int $id
* @property string $name
* @property string $slug
* @property string $langauge
* @property string $content
* @property int $position
* @property int $topped
* @property string $image
* @property string $type // news, article, sales, media
* @property string $keywords
* @property string $descriptions
* @property int $views
*/
class Post extends Model
{
/**
* @var array
*/
protected $guarded = ['id'];
/**
* @var array
*/
protected $casts = [
'topped' => 'boolean',
//'created_at' => 'datetime:j M Y',
'keywords' => 'string',
'descriptions' => 'string'
];
/**
* @param $value
*/
public function setNameAttribute($value)
{
$this->attributes['name'] = $value;
$this->attributes['slug'] = Str::slug($value);
}
/**
* @return string
*/
public function getImage(): string
{
if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image, Date::now()->addMinutes(5)
);
}
return $this->image;
}
return '/images/nophoto.jpg';
}
/**
* @return string
*/
public function getDescription()
{
if (!empty($this->descriptions)) {
return $this->descriptions;
}
return Str::limit(strip_tags($this->content), 250);
}
/**
* @return string
*/
public function getKeywords()
{
if (!empty($this->keywords)) {
return $this->keywords;
}
$title = str_replace(' ', ', ', $this->name);
$description = str_replace(' ', ', ', Str::limit(strip_tags($this->content), 250));
return "{$title}, {$description}";
}
public function getDatePublic()
{
return Carbon::parse($this->created_at)->format('d') . ' '
. Month::LayoutMonth(app()->getLocale(), Carbon::parse($this->created_at)->format('m')) . ' '
. Carbon::parse($this->created_at)->format('Y');
}
}

40
app/Models/Power.php Executable file
View File

@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
/**
* @package App\Models
* @property int $id
* @property array $name
* @property string $power
* @property string $created_at
* @property string $updated_at
*
* @property UsefulInfoItem[] $items
*/
class Power extends Model
{
use HasFactory;
protected $fillable = [
'name',
'power',
];
protected $casts = [
'name' => 'array',
];
public function getName(): string
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
}

20
app/Models/Preview.php Executable file
View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Preview extends Model
{
protected $table = 'previews';
protected $guarded = ['id'];
protected $casts = [
'name' => 'array',
'characteristics' => 'array',
'leader_of_sales' => 'boolean',
'popular' => 'boolean',
];
}

39
app/Models/Problem.php Executable file
View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
/**
* @package App\Models
* @property int $id
* @property array $title
* @property string $created_at
* @property string $updated_at
*
// * @property UsefulInfoItem[] $items
*
*/
class Problem extends Model
{
use HasFactory;
protected $fillable = [
'title',
];
protected $casts = [
'title' => 'array',
];
public function getTitle(): string
{
if (App::isLocale('ru')) {
return (string) $this->title['ru'];
}
return (string) $this->title['uz'];
}
}

566
app/Models/Product.php Executable file
View File

@@ -0,0 +1,566 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Traits\LogsActivity;
/**
* Class Product
*
* @property string|null $name
* @property string|null $body
* @property string|null $short_body
* @property string|null $slug
* @property array|null $colors
* @property array|null $sizes
* @property integer|null $price
* @property boolean|null $published
* @property integer|null $price_discount
* @property integer|null $child_id
* @property string|null $poster
* @property string|null $poster_thumb
* @property boolean|null $popular
* @property boolean|null $leader_of_sales
* @property integer $article_number
* @property float $price_credit
* @property string $currency
* @property integer $brand_id
* @property integer $color_id
* @property integer $count
* @property integer $measurement_id
* @property array|null $keywords
* @property array|null $descriptions
* @property array|null $title_seo
* @property boolean $available
* @property string $data_sheet
* @property boolean $is_ready_solution
*
* @property-read Category $category
* @property-read Brand $brand
* @property-read Color $color
* @property-read Collection|Product[] $childrens
* @property-read Collection|Product|BelongsTo $product
* @property-read Collection|Product[] $childrensColor
* @property-read Collection|Compilation[] $compilations
* @property-read Collection|Comment[] $comments
* @property-read Collection|Characteristic[] $characteristics
* @property-read Collection|Basket[] $baskets
* @property-read Collection|Screen[] $screens
* @property-read Collection|Category[] $categories
*
* @property-read bool $is_favorite
* @property-read bool $is_cart
* @property-read bool $is_available
* @property float $final_price
* @property bool $diff_date
* @property bool $in_cart
*
* @method getName(): string
* @method getTitleSeo(): string
* @method getBody(): string
* @method getShortBody(): string
* @method getKeywords(): string
* @method getPrice(): float
* @method getPoster(): string
*/
class Product extends Model
{
use SoftDeletes, LogsActivity, LogOptionsTrait;
protected $appends = ['isFavorite', 'diffDate', 'isCart', 'onCredit', 'isAvailable', 'finalPrice'];
protected $guarded = ['id'];
protected $casts = [
'name' => 'array',
'body' => 'array',
'short_body' => 'array',
'slug' => 'string',
'sizes' => 'array',
'poster' => 'string',
'poster_thumb' => 'string',
'price' => 'float',
'price_discount' => 'float',
'price_credit' => 'float',
'currency' => 'string',
'article_number' => 'string',
'published' => 'boolean',
'popular' => 'boolean',
'leader_of_sales' => 'boolean',
//'category_id' => 'array',
'brand_id' => 'integer',
'color_id' => 'integer',
'child_id' => 'integer',
'available' => 'boolean',
'count' => 'integer',
'keywords' => 'array',
'descriptions' => 'array',
'title_seo' => 'array',
'is_ready_solution' => 'boolean'
];
protected $hidden = [
'child_id',
'deleted_at'
];
protected static $logName = 'products';
protected static $logOnlyDirty = true;
protected static $logAttributes = ['name', 'price', 'price_discount', 'article_number', 'published', 'available', 'count', 'title_seo', 'price_credit'];
protected static $submitEmptyLogs = false;
public function getFinalPriceAttribute()
{
if (!empty($this->price_discount)) {
return $this->price_discount;
} else {
return $this->price;
}
}
public function getInCartAttribute()
{
$user = getAuthUser();
$userId = $user?->id;
$token = request()->header('X-Application-Token');
$cartQuery = Cart::where('product_id', $this->id);
if (isset($userId)) {
$cartQuery->where('user_id', $userId);
$cart = $cartQuery->first();
if ($cart) {
return $cart->count;
}
}
if (isset($token)) {
$cartQuery->where('token', $token);
$cart = $cartQuery->first();
if ($cart) {
return $cart->count;
}
}
return 0;
}
public function getName(): string
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
public function getTitleSeo(): string
{
if (App::isLocale('ru')) {
return (string) $this->title_seo['ru'];
}
return (string) $this->title_seo['uz'];
}
public function getBody(): string
{
if (App::isLocale('ru')) {
return (string) $this->body['ru'];
}
return (string) $this->body['uz'];
}
public function getShortBody(): string
{
if (App::isLocale('ru')) {
if (!empty($this->descriptions['ru'])) {
return (string) $this->descriptions['ru'];
}
return (string) $this->short_body['ru'];
}
if (!empty($this->descriptions['uz'])) {
return (string) $this->descriptions['uz'];
}
return (string) $this->short_body['uz'];
}
public function getKeywords(): string
{
if (App::isLocale('ru')) {
if (!empty($this->keywords['ru'])) {
$title = str_replace(' ', ', ', $this->getName());
$keywords = $this->keywords['ru'];
return "{$title}, {$keywords}";
}
}
if (!empty($this->keywords['uz'])) {
$title = str_replace(' ', ', ', $this->getName());
$keywords = $this->keywords['uz'];
return "{$title}, {$keywords}";
}
$title = str_replace(' ', ', ', $this->getName());
$description = str_replace(' ', ', ', $this->getShortBody());
return "{$title}, {$description}";
}
public function getPrice($precision = 0): float
{
return round($this->price * $this->getCurrency(), $precision);
}
public function getPoster(): string
{
if (!empty($this->poster)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->poster,
Date::now()->addMinutes(5)
);
}
return '/' . $this->poster;
}
return '/images/no_product.jpg';
}
public function getDataSheet()
{
if (!empty($this->data_sheet) and ($this->data_sheet != null and $this->data_sheet != "null")) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->data_sheet,
Date::now()->addMinutes(5)
);
}
return '/' . $this->data_sheet;
}
return null;
}
public function getPosterThumb(): string
{
if (!empty($this->poster_thumb)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->poster_thumb,
Date::now()->addMinutes(5)
);
}
return '/' . $this->poster_thumb;
}
return '/images/no_product.jpg';
}
/**
* @return float
*/
public function getDiscountPrice()
{
return round($this->price_discount * $this->getCurrency());
}
public function getOnCreditAttribute(): float
{
$price = $this->getPriceCredit();
$credit = $price / 11;
return abs($credit);
}
public function measurement(): BelongsTo
{
return $this->belongsTo(Measurement::class, 'measurement_id', 'id');
}
public function getPriceCredit(): float
{
return round($this->price_credit * $this->getCurrency());
}
private function pmt(float $rate, int $periods, float $present_value, float $future_value = 0.0, bool $beginning = false): float
{
$when = $beginning ? 1 : 0;
if ($rate == 0) {
return - ($future_value + $present_value) / $periods;
}
return - ($future_value + ($present_value * pow(1 + $rate, $periods)))
/
((1 + $rate * $when) / $rate * (pow(1 + $rate, $periods) - 1));
}
public function getCurrency(): int
{
$currency = Currency::latest('id', 'desc')->limit(1)->first();
if ($this->currency == 'dollar') {
return $currency->dollar;
} elseif ($this->currency == 'sum') {
return 1;
} else {
return $currency->euro;
}
}
public function getPriceFormat(): string
{
return number_format($this->price, 0, '', ' ');
}
public function getPriceDiscount(): int
{
return (int) $this->price_discount;
}
public function screen(): BelongsTo
{
return $this->belongsTo(Screen::class, 'id', 'product_id');
}
public function discount(): float
{
$a = $this->price;
$b = $this->price_discount;
$x = (($b * 100) / $a) - 100;
return abs($x);
}
public function getDiffDate(): bool
{
$original_date = date_create(Carbon::parse($this->created_at)->format('Y-m-d'));
$now = date_create(Carbon::now()->format('Y-m-d'));
$diff = date_diff($original_date, $now);
if ($diff->format("%a") <= 10) {
return true;
}
return false;
}
public function categories(): BelongsToMany
{
return $this->belongsToMany(Category::class, 'categories_products');
}
public function getSlug(): string
{
return (string) $this->slug;
}
public function isAviable(): bool
{
return $this->published;
}
public function brand(): BelongsTo
{
return $this->belongsTo(Brand::class, 'brand_id', 'id')->withDefault([
'name' => [
'uz' => 'Brand yo`q',
'ru' => 'Бренд нет'
]
]);
}
public function children(): HasOne
{
return $this->hasOne(self::class, 'child_id', 'id');
}
public function childrens(): HasMany
{
return $this->hasMany(self::class, 'child_id', 'id');
}
public function comments(): HasMany
{
return $this->hasMany(Comment::class)->where('publish', true);
}
public function childrensColor(): HasMany
{
return $this->hasMany(self::class, 'child_id', 'id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function color()
{
return $this->belongsTo(Color::class, 'color_id', 'id');
}
public function screens(): HasMany
{
return $this->hasMany(Screen::class);
}
public function data(): HasOne
{
return $this->hasOne(self::class, 'child_id', 'id');
}
public function product(): BelongsTo
{
return $this->belongsTo(self::class, 'child_id', 'id');
}
public function compilations(): BelongsToMany
{
return $this->belongsToMany(Compilation::class, 'compilation_products');
}
public function getIsFavoriteAttribute(): bool
{
$user = request()->user();
if (!empty($user)) {
$favorite = $this->belongsToMany(User::class, 'products_users')->where('user_id', $user->id)->where('product_id', $this->id)->first();
if (!empty($favorite)) {
return true;
}
}
if (!empty(getAuthUser())) {
$favorite = $this->belongsToMany(User::class, 'products_users')->where('user_id', getAuthUser()->id)->where('product_id', $this->id)->first();
if (!empty($favorite)) {
return true;
}
}
return false;
}
public function getIsAvailableAttribute(): bool
{
if ($this->available && $this->count > 0) {
return true;
}
return false;
}
public function getIsCartAttribute(): bool
{
$user = getAuthUser();
$userId = $user?->id;
$token = request()->header('X-Application-Token');
$cartQuery = Cart::where('product_id', $this->id);
if (isset($userId)) {
$cartQuery->where('user_id', $userId);
$cart = $cartQuery->first();
if ($cart) {
return true;
}
}
if (isset($token)) {
$cartQuery->where('token', $token);
$cart = $cartQuery->first();
if ($cart) {
return true;
}
}
return false;
}
public function getDiffDateAttribute(): bool
{
$original_date = date_create(Carbon::parse($this->created_at)->format('Y-m-d'));
$now = date_create(Carbon::now()->format('Y-m-d'));
$diff = date_diff($original_date, $now);
if ($diff->format("%a") <= 10) {
return true;
}
return false;
}
public function characteristics(): BelongsToMany
{
return $this->belongsToMany(Characteristic::class, 'characteristics_products')->withPivot(['value']);
}
// -- Scopes --
public function scopeBrand($query, $brand_id): mixed
{
return $query->where('brand_id', $brand_id);
}
public function scopeIsAvailable($query): mixed
{
return $query->where('available', true)->where('count', '>', 0);
}
public function scopePublished($query): mixed
{
return $query->where('published', true)->whereNull('deleted_at');
}
public function scopeNotChilds($query): mixed
{
return $query->whereNull('child_id');
}
public function scopeSearchFilter($query, $id, $brand, $category, $published, $article_number, $category_id, $name)
{
return $query->when($id ?? null, function ($query, $id) {
$query->where('id', $id);
})
->whereHas('categories', function ($query) use ($category, $category_id) {
$query->when($category ?? null, function ($query, $category) use ($category_id) {
$query->whereIn('id', $category_id);
});
})->when($published ?? null, function ($query, $published) {
if ($published == 2) {
$query->where('published', false);
} else {
$query->where('published', true);
}
})->when($name ?? null, function ($query, $name) {
$query->where('name->ru', 'ilike', '%' . $name . '%');
})->when($article_number ?? null, function ($query, $article_number) {
$query->where('article_number', $article_number);
})->notChilds();
}
}

49
app/Models/Region.php Executable file
View File

@@ -0,0 +1,49 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Support\Facades\App;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
class Region extends Model
{
use LogsActivity, LogOptionsTrait;
protected $guarded = ['id'];
protected $casts = [
'name' => 'array',
'cash' => 'boolean'
];
protected static $logName = 'regions';
protected static $logOnlyDirty = true;
protected static $logAttributes = ['name', 'cash'];
protected static $submitEmptyLogs = false;
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function cities()
{
return $this->hasMany(City::class, 'region_id', 'id');
}
public function getName(): string
{
return (string) $this->name[App::getLocale()] ?? null;
}
public function deliveryPrice()
{
return $this->hasMany(DeliveryPrice::class, 'region_id', 'id');
}
public function getDeliveryPrice($powerId): ?float
{
$deliveryPrice = collect($this->deliveryPrice)->where('power_id', $powerId)->first();
return $deliveryPrice ? $deliveryPrice['price'] : null;
}
}

36
app/Models/Role.php Executable file
View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
class Role extends Model
{
use LogsActivity, LogOptionsTrait;
protected $fillable = [
'name',
'permissions'
];
protected $casts = [
'permissions' => 'array'
];
protected static $logName = 'roles';
protected static $logOnlyDirty = true;
protected static $logAttributes = ['name', 'permissions'];
protected static $submitEmptyLogs = false;
public function staff()
{
return $this->hasOne(Staff::class, 'role_id', 'id');
}
public function hasPermission($type, $permissions): bool
{
return $this->permissions[$type][$permissions] ?? false;
}
}

92
app/Models/Screen.php Executable file
View File

@@ -0,0 +1,92 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* Class Screen
*
* @property string|null $name
* @property string|null $path
* @property string|null $path_thumb
* @property float|null $size
*
* @mixin
*/
class Screen extends Model
{
public $timestamps = false;
/**
* @var array
*/
protected $fillable = [
'name', 'path', 'path_thumb', 'size', 'product_id', 'type'
];
/**
* @var array
*/
protected $casts = [
'name' => 'string',
'path' => 'string',
'path_thumb' => 'string',
'size' => 'float',
'product_id' => 'integer',
'type' => 'string'
];
/**
* @return string
*/
public function getName(): string
{
return (string) $this->name;
}
/**
* @return string
*/
public function getPath(): string
{
if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->path, Date::now()->addMinutes(5)
);
}
return (string) $this->path;
}
return (string) 'image/no_screen.png';
}
/**
* @return string
*/
public function getPathThumb(): string
{
if (!empty($this->path_thumb)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->path_thumb, Date::now()->addMinutes(5)
);
}
return (string) $this->path_thumb;
}
return (string) 'image/no_screen_thumb.png';
}
/**
* @return float
*/
public function getSize(): float
{
return (float) $this->size;
}
}

80
app/Models/Service.php Executable file
View File

@@ -0,0 +1,80 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property int $id
* @property array $name
* @property string $image
* @property string $status
* @property string $type
* @property int $position
* @property bool $is_power
* @property bool $with_problem
*
* @method getImage(): string
* @method getName(): string
*
* @property Status $getStatus
*/
class Service extends Model
{
use HasFactory;
protected $fillable = [
'name',
'image',
'status',
'type',
'is_power',
'position',
'with_problem'
];
protected $casts = [
'name' => 'array',
'is_power' => 'boolean',
'with_problem' => 'boolean'
];
public function getStatus()
{
return $this->belongsTo(Status::class, 'status', 'slug');
}
public function getName(): string
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
public function getImage(): string
{
if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image,
Date::now()->addMinutes(5)
);
}
return (string) $this->image;
}
return (string) 'images/no_brend.png';
}
public function problems()
{
return $this->belongsToMany(Problem::class, 'service_problems');
}
}

34
app/Models/ServiceProblem.php Executable file
View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @package App\Models
* @property int $id
* @property int $service_id
* @property int $problem_id
*/
class ServiceProblem extends Model
{
use HasFactory;
protected $table = 'service_problems';
protected $fillable = [
'service_id',
'problem_id',
];
public function service()
{
return $this->belongsTo(Service::class);
}
public function problem()
{
return $this->belongsTo(Problem::class);
}
}

74
app/Models/ServiceRequest.php Executable file
View File

@@ -0,0 +1,74 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @package App\Models
* @property int $id
* @property int $service_id
* @property int|null $power_id
* @property int $city_id
* @property int $user_id
* @property int|null $problem_id
* @property string|null $comment
* @property int $phone
* @property string $full_name
* @property string $status // pending, accepted, closed
* @property \Illuminate\Support\Carbon $created_at
* @property \Illuminate\Support\Carbon $updated_at
*
* @property-read Service $service
* @property-read Power $power
* @property-read City $city
* @property-read Status $getStatus
*/
class ServiceRequest extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'service_id',
'power_id',
'city_id',
'comment',
'user_id',
'phone',
'full_name',
'status',
'problem_id'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function getStatus()
{
return $this->belongsTo(Status::class, 'status', 'slug');
}
public function service()
{
return $this->belongsTo(Service::class);
}
public function problem()
{
return $this->belongsTo(Problem::class, 'problem_id');
}
public function power()
{
return $this->belongsTo(Power::class);
}
public function city()
{
return $this->belongsTo(City::class);
}
}

212
app/Models/Setting.php Executable file
View File

@@ -0,0 +1,212 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Support\Facades\App;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
/**
* Class Setting
*
* @property string|null $title
* @property string|null $keywords
* @property string|null $description
* @property array|null $phone
* @property string|null $email
* @property string|null $address
* @property array|null $socials
* @property string|null $group_id
*
* @mixin Model
*/
class Setting extends Model
{
use LogsActivity, LogOptionsTrait;
/**
* @var array
*/
protected $guarded = ['id'];
protected $casts = [
'title' => 'array',
'keywords' => 'array',
'description' => 'array',
'phone' => 'array',
'address' => 'array',
'socials' => 'array',
'email' => 'string',
'day_delivery' => 'integer',
'price_delivery' => 'integer',
'landmark' => 'array',
'permissions' => 'array',
'pickup_text' => 'array',
'other' => 'array',
'links' => 'array',
'buy_one' => 'boolean'
];
protected static $logName = 'settings';
protected static $logOnlyDirty = true;
protected static $logAttributes = [
'title',
'keywords',
'description',
'phone',
'address',
'socials',
'email',
'day_delivery',
'price_delivery',
'landmark',
'permissions',
'pickup_text',
'other',
'pickup',
'delivery',
'buy_one'
];
protected static $submitEmptyLogs = false;
/**
* @return string
*/
public function getTitle(): string
{
if (App::isLocale('ru')) {
return (string) $this->title['ru'];
}
return (string) $this->title['uz'];
}
/**
* @return string
*/
public function getKeywords(): string
{
if (App::isLocale('ru')) {
return (string) $this->keywords['ru'];
}
return (string) $this->keywords['uz'];
}
/**
* @return string
*/
public function getDescription(): string
{
if (App::isLocale('ru')) {
return (string) $this->description['ru'];
}
return (string) $this->description['uz'];
}
/**
* @return string
*/
public function getAddress(): string
{
if (App::isLocale('ru')) {
return (string) $this->address['ru'];
}
return (string) $this->address['uz'];
}
/**
* @return string
*/
public function getLandmark()
{
if (App::isLocale('ru')) {
return (string) $this->address['ru'];
}
return (string) $this->address['uz'];
}
/**
* @return int
*/
public function getPriceDelivery()
{
return (int) $this->price_delivery;
}
public function getDayDelivery()
{
return (int) $this->day_delivery;
}
/**
* @return string
*/
public function getPhone(): string
{
return (string) $this->phone['default'];
}
/**
* @return string
*/
public function getPhoneOther(): string
{
return (string) $this->phone['other'];
}
/**
* @return string
*/
public function getEmail(): string
{
return (string) $this->email;
}
/**
* @return string
*/
public function getTelegram(): string
{
return (string) $this->socials['telegram'];
}
/**
* @return string
*/
public function getFacebook(): string
{
return (string) $this->socials['facebook'];
}
/**
* @return string
*/
public function getInstagram(): string
{
return (string) $this->socials['instagram'];
}
/**
* @return string
*/
public function getYoutube()
{
return (string) $this->socials['youtube'];
}
/**
* @return string
*/
public function getOkru()
{
return (string) $this->socials['okru'];
}
}

63
app/Models/Slider.php Executable file
View File

@@ -0,0 +1,63 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Traits\LogsActivity;
class Slider extends Model
{
use LogsActivity, LogOptionsTrait;
protected $fillable = [
'name',
'image',
'language',
'link',
'type',
'views',
'placement',
'published',
'position'
];
protected $casts = [
'published' => 'boolean'
];
protected static $logName = 'sliders';
protected static $logOnlyDirty = true;
protected static $submitEmptyLogs = false;
protected static $logAttributes = [
'name',
'image',
'language',
'link',
'type',
'placement',
'published',
'position'
];
public function getImage(): string
{
if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image, Date::now()->addMinutes(5)
);
}
return $this->image;
}
return '/images/nophoto.jpg';
}
public function scopePublished($query)
{
return $query->where('published', true);
}
}

60
app/Models/SpecialOffer.php Executable file
View File

@@ -0,0 +1,60 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Traits\LogsActivity;
class SpecialOffer extends Model
{
use LogsActivity, LogOptionsTrait;
protected $fillable = [
'name',
'description',
'link',
'image'
];
protected $casts = [
'name' => 'array',
'description' => 'array'
];
protected static $logName = 'special_offer';
protected static $logOnlyDirty = true;
protected static $submitEmptyLogs = false;
protected static $logAttributes = [
'name',
'description',
'link',
'image'
];
public function getName(): string
{
return (string) $this->name[app()->getLocale()] ?? null;
}
public function getDescription(): string
{
return (string) $this->description[app()->getLocale()] ?? null;
}
public function getImage(): string
{
if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image, Date::now()->addMinutes(5)
);
}
return (string) $this->image;
}
return (string) 'images/nophoto.png';
}
}

62
app/Models/Staff.php Executable file
View File

@@ -0,0 +1,62 @@
<?php
namespace App\Models;
use App\Traits\LogOptionsTrait;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Activitylog\Traits\LogsActivity;
class Staff extends Authenticatable
{
use LogsActivity, LogOptionsTrait;
protected $fillable = [
'username',
// 'email',
'password',
'role_id'
];
protected static $logName = 'staffs';
protected static $logOnlyDirty = true;
protected static $submitEmptyLogs = false;
protected static $logAttributes = [
'username',
'password',
'role'
];
public function setPasswordAttribute($password)
{
if ( !empty($password) ) {
$this->attributes['password'] = bcrypt($password);
}
}
public function role()
{
return $this->belongsTo(Role::class, 'role_id', 'id')->withDefault([
'name' => 'Удалено'
]);
}
public function hasPermission(string $type, string $permission) : bool
{
return $this->role->hasPermission($type, $permission);
}
public function isAdmin()
{
return $this->role_id === 1;
}
// public function isModerator()
// {
// return $this->roles()->first()->pivot->role_id === 4;
// }
//
// public function isContentManager()
// {
// return $this->roles()->first()->pivot->role_id === 3;
// }
}

20
app/Models/Status.php Executable file
View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @package App\Models
* @property int $id
* @property string $slug // unique
* @property string $font_color
* @property string $bg_color
*/
class Status extends Model
{
use HasFactory;
protected $guarded = ['id'];
}

66
app/Models/UsefulInfo.php Executable file
View File

@@ -0,0 +1,66 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property int $id
* @property array $name
* @property string $image
* @property int $position
* @property string $created_at
* @property string $updated_at
*
* @property UsefulInfoItem[] $items
*
*/
class UsefulInfo extends Model
{
use HasFactory;
protected $table = 'useful_infos';
protected $fillable = [
'name',
'image',
'position'
];
protected $casts = [
'name' => 'array',
];
public function items()
{
return $this->hasMany(UsefulInfoItem::class);
}
public function getImage(): string
{
if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->image, Date::now()->addMinutes(5)
);
}
return (string) $this->image;
}
return (string) 'images/no_brend.png';
}
public function getName(): string
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
}

90
app/Models/UsefulInfoItem.php Executable file
View File

@@ -0,0 +1,90 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property int $id
* @property int $useful_info_id
* @property array $name
* @property array $description
* @property string $video_url
* @property string $link_url
* @property string $file_url
* @property string $created_at
* @property string $updated_at
*
* @property UsefulInfo $usefulInfo
*
* @method string getName()
* @method string getDescription()
* @method string getFile()
*/
class UsefulInfoItem extends Model
{
use HasFactory;
protected $table = 'useful_info_items';
protected $fillable = [
'useful_info_id',
'name',
'description',
'video_url',
'link_url',
'file_url',
];
protected $casts = [
'name' => 'array',
'description' => 'array',
];
public function usefulInfo()
{
return $this->belongsTo(UsefulInfo::class);
}
public function getName(): string
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
public function getFile(): string
{
if (!empty($this->file_url)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
return Storage::temporaryUrl(
$this->file_url,
Date::now()->addMinutes(5)
);
}
return '/' . $this->file_url;
}
return '/images/no_product.jpg';
}
public function getDescription(): string
{
if (isset($this->description['uz']) && isset($this->description['ru'])) {
if (App::isLocale('ru')) {
return (string) $this->description['ru'];
}
return (string) $this->description['uz'];
}
return '';
}
}

291
app/Models/User.php Executable file
View File

@@ -0,0 +1,291 @@
<?php
namespace App\Models;
use App\Models\Address;
use App\Models\Cart;
use App\Models\Order;
use App\Models\Product;
use App\Models\Role;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* @package App\Models
* @property int $id
* @property string $first_name
* @property string $last_name
* @property string $avatar
* @property int $role_id
* @property string $email
* @property string $password
* @property int $phone
* @property int $verify_code
* @property int $verified
* @property int $gender
* @property string $birth_day
* @property string $postal_address
* @property int $category_id
* @property int $notification
* @property string $language
* @property int $step
* @property string $ip
* @property string $created_at
* @property string $updated_at
* @property string $deleted_at
*
* @property UserLegalInfo|HasOne $legalInfo
* @property Role|BelongsTo $role
* @property Role[]|BelongsToMany $roles
* @property Address[]|HasMany $addresses
* @property Address|BelongsTo $address
* @property Order[]|HasMany $orders
* @property Product[]|BelongsToMany $products
* @property Cart[]|HasMany $cart
*
*/
class User extends Authenticatable
{
use HasApiTokens, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = ['id'];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'first_name' => 'string',
'last_name' => 'string',
'phone' => 'string',
'verify_code' => 'integer',
'step' => 'integer',
'ip' => 'string',
'role_id' => 'integer',
'gander' => 'boolean',
'language' => 'string',
'category_id' => 'integer',
'avatar' => 'string',
'notification' => 'boolean',
'verified' => 'boolean',
];
public function legalInfo(): HasOne
{
return $this->hasOne(UserLegalInfo::class, 'user_id', 'id');
}
/**
* @param $password
*/
public function setPasswordAttribute($password)
{
if (!empty($password)) {
$this->attributes['password'] = bcrypt($password);
}
}
/**
* @return string
*/
public function getFirstName(): string
{
return (string) $this->first_name;
}
/**
* @return bool
*/
public function isRegistered(): bool
{
return $this->step == 3 ? true : false;
}
/**
* @return string
*/
public function getLastName(): string
{
return (string) $this->last_name;
}
/**
* @return int
*/
public function getPhone(): int
{
return (int) $this->phone;
}
/**
* @return string
*/
public function getIp(): string
{
return (string) $this->ip;
}
/**
* @return bool
*/
public function isVerify(): bool
{
return $this->verify_code;
}
/**
* @return bool
*/
public function isNotVerify(): bool
{
return ! $this->isVerify();
}
/**
* @param int $code
* @return bool
*/
public function isVerifyCode(int $code): bool
{
return $this->verify_code == $code;
}
/**
* @param string $code
* @return bool
*/
public function isNotVerifyCode(string $code): bool
{
return ! $this->isVerifyCode($code);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function addresses(): HasMany
{
return $this->hasMany(Address::class);
}
public function address(): BelongsTo
{
return $this->belongsTo(Address::class, 'id', 'user_id')->withDefault([
'city' => '',
'region' => '',
'address' => '',
'house' => '',
'apartment' => '',
'floor' => '',
'entrance' => ''
]);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function orders(): HasMany
{
return $this->hasMany(Order::class);
}
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'products_users');
}
public function cart(): HasMany
{
return $this->hasMany(Cart::class);
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class, 'role_user')->withPivot('role_id');
}
public function role(): BelongsTo
{
return $this->belongsTo(Role::class);
}
/**
* @return string
*/
public function getFullName(): string
{
return (string) $this->first_name . ' ' . $this->last_name;
}
/**
* @param $query
* @return mixed
*/
public function scopeSteped($query)
{
return $query->where('step', 3);
}
/**
* @param $query
* @param $phone
* @return mixed
*/
public function scopeFindByPhone($query, $phone)
{
return $query->where('phone', $phone);
}
/**
* @param $query
* @param $date_from
* @param $date_to
* @param $sort_type
* @return mixed
*/
public function scopeFilterByDate($query, $date_from, $date_to, $sort_type)
{
if (!is_null($date_from)) {
$date_from = Carbon::parse($date_from)->format('Y-m-d 00:00:01');
if ($date_to) {
$date_to = Carbon::parse($date_to)->format('Y-m-d 23:59:59');
} else {
$date_to = Carbon::now()->format('Y-m-d 23:59:59');
}
$query->whereBetween($sort_type, [$date_from, $date_to]);
}
return $query;
}
/**
* @param $query
* @param $search_id
* @param $search_phone
* @param $search_ip
* @return mixed
*/
public function scopeSearch($query, $search_id, $search_phone, $search_ip)
{
if (!is_null($search_id))
$query->where('id', 'ilike', '%' . $search_id . '%');
elseif (!is_null($search_phone))
$query->where('phone', 'ilike', '%' . $search_phone . '%');
elseif (!is_null($search_ip))
$query->where('ip', 'ilike', '%' . $search_ip . '%');
return $query;
}
}

51
app/Models/UserLegalInfo.php Executable file
View File

@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @package App\Models
* @property int $id
* @property int $order_id
* @property string $company_name
* @property string $inn
* @property string $bank_name
* @property string $mfo
* @property string $oked
* @property string $payment_account
* @property string $address
* @property string $email
* @property string $phone
* @property string $director_full_name
*
* @property Order $order
*/
class UserLegalInfo extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'user_legal_infos';
protected $fillable = [
'user_id',
'company_name',
'inn',
'bank_name',
'mfo',
'oked',
'payment_account',
'address',
'email',
'phone',
'director_full_name',
];
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
}