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

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class AddressResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'city' => new CityWithRegionResource($this->city),
'home' => $this->home,
'landmark' => $this->landmark,
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Resources\Api;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TransactionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->paycom_transaction_id,
'time' => $this->paycom_time,
'amount' => $this->amount,
'account' => [
'order_id' => $this->order_id,
],
'create_time' => intval($this->paycom_time),
'perform_time' => intval($this->perform_time_unix),
'cancel_time' => intval($this->cancel_time) ?? 0,
'transaction' => $this->id,
'state' => $this->state,
'reason' => $this->reason
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BranchResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'address' => $this->address[$lang],
'phone' => $this->phone,
'map' => $this->map,
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BrandPaginationResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'pagination' => [
'current' => $this->currentPage(),
'previous' => $this->currentPage() > 1 ? $this->currentPage() - 1 : null,
'next' => $this->hasMorePages() ? $this->currentPage() + 1 : null,
'total' => $this->lastPage(),
'perPage' => $this->perPage(),
'totalItems' => $this->total(),
],
'data' => BrandResource::collection($this->items())->all()
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BrandResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'image' => $this->getImage(),
'slug' => $this->slug,
];
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CartResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request)
{
$lang = $request->header('Accept-Language') ?? 'ru';
// get currency from cache
$currency = cache()->get('currency');
if ($this->price_discount) {
$discount_percent = 100 - round($this->price_discount / $this->price * 100);
} else {
$discount_percent = 0;
}
if ($this->product->price_discount) {
$price_total = $this->product->price_discount * $this->count * $currency->dollar;
} else {
$price_total = $this->product->price * $this->count * $currency->dollar;
}
return [
'id' => $this->id,
'name' => $this->product->name[$lang],
'price' => ceiling($this->product->price * $currency->dollar, 100),
'price_usd' => floatval($this->product->price),
'price_discount' => $this->product->price_discount != null ? $this->product->price_discount * $currency->dollar : null,
'price_discount_usd' => floatval($this->product->price_discount != null ? ceiling($this->product->price_discount, 100) : null),
'discount_percent' => $discount_percent,
'price_total' => ceiling($price_total, 100),
'poster' => $this->product->getPoster(),
'poster_thumb' => $this->product->getPosterThumb(),
'count' => $this->count,
'available_count' => $this->product->count,
'is_available' => $this->product->count <= $this->count ? false : true,
'product_id' => $this->product->id,
'product_count' => $this->product->count,
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CategoryResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'image' => $this->getImage(),
'parent_id' => $this->parent_id,
'parents' => CategoryResource::collection($this->parents),
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CityResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CityWithRegionResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'region' => new RegionResource($this->region),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CompanyResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'company_name' => $this->company_name,
'inn' => $this->inn,
'mfo' => $this->mfo,
'bank_name' => $this->bank_name,
'oked' => $this->oked,
'address' => $this->address[$lang],
'director_full_name' => $this->director_full_name,
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CompilationResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'title' => $this->title[$lang],
'products' => ProductResource::collection($this->products),
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class FavoritePaginationResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'pagination' => [
'current' => $this->currentPage(),
'previous' => $this->currentPage() > 1 ? $this->currentPage() - 1 : null,
'next' => $this->hasMorePages() ? $this->currentPage() + 1 : null,
'total' => $this->lastPage(),
'perPage' => $this->perPage(),
'totalItems' => $this->total(),
],
'data' => FavoriteResource::collection($this->items())->all()
];
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class FavoriteResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request)
{
return new ProductResource($this->product);
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Http\Resources;
use App\Models\Order;
use Carbon\CarbonPeriod;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\DB;
class OrderCount extends JsonResource
{
protected $date_from;
protected $date_to;
public function __construct($date_from,$date_to)
{
$this->date_from = $date_from;
$this->date_to = $date_to;
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'labels' => $this->labels(),
'datasets' => [
[
'label' => Order::status(0),
'data' => $this->counts(0),
'borderColor' => Order::color(0),
'fill' => false
],
[
'label' => Order::status(1),
'data' => $this->counts(1),
'borderColor' => Order::color(1),
'fill' => false
],
[
'label' => Order::status(2),
'data' => $this->counts(2),
'borderColor' => Order::color(2),
'fill' => false
],
[
'label' => Order::status(3),
'data' => $this->counts(3),
'borderColor' => Order::color(3),
'fill' => false
],
[
'label' => Order::status(4),
'data' => $this->counts(4),
'borderColor' => Order::color(4),
'fill' => false
],
]
];
}
public function labels(){
$period = CarbonPeriod::create($this->date_from,$this->date_to);
$dates =[];
foreach ($period as $date) {
$dates[] = $date->format('Y-m-d');
}
return $dates;
}
public function counts($status){
$count = Order::select(DB::raw('count(id) as count'),DB::raw('DATE(created_at) as date'))
->where('status',$status)
->groupBy('date')
->whereBetween('created_at',[$this->date_from,$this->date_to])
->pluck('count','date');
$chart = [];
$period = $this->labels();
foreach ($period as $date) {
$chart[] = (!empty($count[$date])) ? $count[$date]:0;
}
return $chart;
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderPaginationResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'pagination' => [
'current' => $this->currentPage(),
'previous' => $this->currentPage() > 1 ? $this->currentPage() - 1 : null,
'next' => $this->hasMorePages() ? $this->currentPage() + 1 : null,
'total' => $this->lastPage(),
'perPage' => $this->perPage(),
'totalItems' => $this->total(),
],
'data' => OrderResource::collection($this->items())->all()
];
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace App\Http\Resources;
use App\Models\Order;
use Carbon\CarbonPeriod;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\DB;
class OrderPrice extends JsonResource
{
protected $date_from;
protected $date_to;
public function __construct($date_from,$date_to)
{
$this->date_from = $date_from;
$this->date_to = $date_to;
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'labels' => $this->labels(),
'datasets' => [
[
'label' => Order::status(0),
'data' => $this->prices(0),
'borderColor' => Order::color(0),
'fill' => false
],
[
'label' => Order::status(1),
'data' => $this->prices(1),
'borderColor' => Order::color(1),
'fill' => false
],
[
'label' => Order::status(2),
'data' => $this->prices(2),
'borderColor' => Order::color(2),
'fill' => false
],
[
'label' => Order::status(3),
'data' => $this->prices(3),
'borderColor' => Order::color(3),
'fill' => false
],
[
'label' => Order::status(4),
'data' => $this->prices(4),
'borderColor' => Order::color(4),
'fill' => false
],
]
];
}
public function labels(){
$period = CarbonPeriod::create($this->date_from,$this->date_to);
$dates =[];
foreach ($period as $date) {
$dates[] = $date->format('Y-m-d');
}
return $dates;
}
public function prices($status){
$count = Order::select(DB::raw('SUM(price_total) as price'),DB::raw('DATE(created_at) as date'))
->where('status',$status)
->groupBy('date')
->whereBetween('created_at',[$this->date_from,$this->date_to])
->pluck('price','date');
$chart = [];
$period = $this->labels();
foreach ($period as $date) {
$chart[] = (!empty($count[$date])) ? $count[$date]:0;
}
return $chart;
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderProductResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
// get currency from cache
$currency = cache()->get('currency');
return [
'id' => $this->id,
'name' => $this->product->name[$lang],
'count' => $this->count,
'price' => ceiling($this->final_price * $currency->dollar, 100),
'total_price' => ceiling($this->final_price * $this->count * $currency->dollar, 100),
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\App;
class OrderResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
// Set the application locale to the retrieved language
App::setLocale($lang);
return [
'id' => $this->id,
'status' => new StatusResource($this->getStatus),
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
'total_amount' => $this->price_total,
];
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderShowResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
if ($this->client_type == 'physical') {
$client_information = [
'full_name' => $this->full_name,
'phone' => $this->phone,
];
} else {
$client_information = null;
}
if (in_array($this->payment_status, ['waiting', 'processing'])) {
if ($this->payment_type == 'click') {
$merchant_id = env("CLICK_MERCHANT_ID");
$service_id = env("CLICK_SERVICE_ID");
$pay_url = "https://my.click.uz/services/pay?service_id={$service_id}&merchant_id={$merchant_id}&amount={$this->billing->amount}&transaction_param={$this->billing->id}";
} else {
$amount = $this->billing->amount * 100;
$payme_url = "https://checkout.paycom.uz/". base64_encode("m=66faa5c44f9ee150b7ff81cf;ac.key={$this->billing->id};a={$amount}");
$pay_url = $payme_url;//'https://checkout.payme.uz';
}
} else {
$pay_url = null;
}
return [
'id' => $this->id,
'pay_url' => $pay_url,
'status' => new StatusResource($this->getStatus),
'payment_type' => $this->payment_type,
'payment_status' => new StatusResource($this->getPaymentStatus),
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
'delivery_type' => $this->delivery_type,
'client_type' => $this->client_type,
'total_amount' => $this->price_total,
'products' => OrderProductResource::collection($this->products),
'address' => new AddressResource($this->address),
'legal_information' => $this->client_type == 'legal' ? $this->legalInfo : null,
'client_information' => $client_information,
'branch' => new BranchResource($this->branch),
'with_installation' => $this->with_installation,
'with_didox' => $this->with_didox,
'price_products' => $this->price_products,
'price_delivery' => $this->price_delivery,
'price_master' => $this->price_master,
"contract" => $this->contracts()->latest()->first()?->getPath()
];
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PageResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'body' => $this->body[$lang],
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PartnerRequestResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'partner' => new PartnerResource($this->partner),
'city' => new CityWithRegionResource($this->city),
'comment' => $this->comment,
'phone' => $this->phone,
'full_name' => $this->full_name,
'user' => new UserResource($this->user),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PartnerResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'image' => $this->getImage(),
'status' => new StatusResource($this->getStatus),
'is_price' => $this->is_price,
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PartnerShowResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'image' => $this->getImage(),
'status' => new StatusResource($this->getStatus),
'description' => $this->description ? $this->description[$lang] : null,
'video_url' => isset($this->video_url) ? $this->video_url : null,
'is_price' => $this->is_price,
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PaymentSystemItemResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'title' => $this->title[$lang],
'logo' => $this->getLogo(),
'slug' => $this->slug,
'description' => $this->description ? $this->description[$lang] : null,
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PaymentSystemResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'title' => $this->title[$lang],
'systems' => PaymentSystemItemResource::collection($this->items),
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PowerResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'power' => $this->power,
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProblemResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'title' => $this->title[$lang],
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductCharacteristicResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'type' => $this->type,
'pivot' => [
'value' => $this->pivot->value,
],
];
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Services\API\ProductService;
class ProductDetailResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
$service = new ProductService($this);
// get currency from cache
$currency = cache()->get('currency');
if ($this->price_discount) {
$discount_percent = 100 - round($this->price_discount / $this->price * 100);
} else {
$discount_percent = 0;
}
$in_cart = $this->in_cart;
return [
'id' => $this->id,
'name' => $this->name[$lang],
'price' => ceiling($this->price * $currency->dollar, 100),
'price_usd' => $this->price,
'price_discount' => ceiling($this->price_discount * $currency->dollar, 100),
'price_discount_usd' => $this->price_discount,
'discount_percent' => $discount_percent,
'published' => $this->published,
'is_ready_solution' => $this->is_ready_solution,
'is_leader_of_sales' => $this->leader_of_sales,
'poster' => $this->getPoster(),
'poster_thumb' => $this->getPosterThumb(),
"is_install" => $service->isInstall(),
'is_favorite' => $this->is_favorite,
'is_cart' => $this->is_cart,
'is_available' => $this->count > 0 ? $this->available : false,
'count' => $this->count,
"measurement" => $this->measurement()->get()->first()?->getName(),
'data_sheet' => $this->getDataSheet(),
'screens' => $this->childrens->first() ? ProductScreenResource::collection($this->childrens->first()->screens) : [],
'characteristics' => $this->characteristics->count() > 0 ? ProductCharacteristicResource::collection($this->characteristics) : null,
'in_cart' => $in_cart,
'short_description' => $this->short_body[$lang],
'description' => $this->body[$lang],
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductPaginationResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'pagination' => [
'current' => $this->currentPage(),
'previous' => $this->currentPage() > 1 ? $this->currentPage() - 1 : null,
'next' => $this->hasMorePages() ? $this->currentPage() + 1 : null,
'total' => $this->lastPage(),
'perPage' => $this->perPage(),
'totalItems' => $this->total(),
],
'data' => ProductResource::collection($this->items())->all()
];
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
// get currency from cache
$currency = cache()->get('currency');
if ($this->price_discount) {
$discount_percent = 100 - round($this->price_discount / $this->price * 100);
} else {
$discount_percent = 0;
}
return [
'id' => $this->id,
'name' => $this->name[$lang],
'price' => ceiling($this->price * $currency->dollar, 100),
'price_discount' => ceiling($this->price_discount * $currency->dollar, 100),
'discount_percent' => $discount_percent,
'is_leader_of_sales' => $this->leader_of_sales,
'poster' => $this->getPoster(),
'poster_thumb' => $this->getPosterThumb(),
'is_favorite' => $this->is_favorite,
'is_cart' => $this->is_cart,
'count' => $this->count,
'power' => $this->power,
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductScreenResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'path' => $this->getPath(),
'path_thumb' => $this->getPathThumb(),
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class RegionResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class RegionWithCityResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'cities' => CityResource::collection($this->cities),
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class RequestListResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'status' => new StatusResource($this->getStatus),
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class RequestPaginationResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'pagination' => [
'current' => $this->currentPage(),
'previous' => $this->currentPage() > 1 ? $this->currentPage() - 1 : null,
'next' => $this->hasMorePages() ? $this->currentPage() + 1 : null,
'total' => $this->lastPage(),
'perPage' => $this->perPage(),
'totalItems' => $this->total(),
],
'data' => RequestListResource::collection($this->items())->all()
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ServiceProblemResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'title' => $this->title[$lang],
];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ServiceRequestResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
if ($this->problem) {
$problem = new ProblemResource($this->problem);
} else {
$problem = null;
}
return [
'id' => $this->id,
'service' => new ServiceResource($this->service),
'power' => $this->power ? [
'id' => $this->power->id,
'name' => $this->power->name[$lang],
'power' => $this->power->power,
] : null,
'city' => new CityWithRegionResource($this->city),
'comment' => $this->comment,
'phone' => $this->phone,
'full_name' => $this->full_name,
'status' => new StatusResource($this->getStatus),
'problem' => $problem,
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ServiceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'image' => $this->getImage(),
'type' => $this->type,
'status' => new StatusResource($this->getStatus),
'is_power' => $this->is_power,
'with_problem' => $this->with_problem,
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
'problems' => count($this->problems) > 0 ? ServiceProblemResource::collection($this->problems) : [],
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class SliderResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'image' => $this->getImage(),
'position' => $this->position,
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\App;
class StatusResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
// Set the application locale to the retrieved language
App::setLocale($lang);
return [
'slug' => $this->slug,
'translation' => trans('admin.statuses.' . $this->slug),
'font_color' => $this->font_color,
'bg_color' => $this->bg_color,
];
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UsefulInfoItemResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
if (isset($this->description['uz']) && isset($this->description['ru'])) {
$description = $this->description[$lang];
} else {
$description = null;
}
return [
'id' => $this->id,
'name' => $this->name[$lang],
'description' => $description,
'video_url' => isset($this->video_url) ? $this->video_url : null,
'link_url' => isset($this->link_url) ? $this->link_url : null,
'file_url' => isset($this->file_url) ? $this->getFile() : null,
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UsefulInfoResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$lang = $request->header('Accept-Language') ?? 'ru';
return [
'id' => $this->id,
'name' => $this->name[$lang],
'image' => $this->getImage(),
'position' => $this->position,
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
public static $wrap = false;
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'middle_name' => $this->middle_name,
'avatar' => $this->avatar ? asset($this->avatar) : null,
'phone' => $this->phone,
'email' => $this->email,
'gender' => $this->gender,
'language' => $this->language,
'birth_day' => $this->birth_day,
];
}
}