Refactor code for consistency and clarity; update seeder comments, enhance error handling, and improve API routes. Added 'original' field to ProductMediaResource and adjusted various formatting issues across multiple files.
This commit is contained in:
@@ -20,7 +20,7 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->call(new PruneStaleAttachments)->daily();
|
||||
|
||||
// IF any warnings unresolved warnings exists, send notify me
|
||||
$schedule->call(new WarnDev)->dailyAt('16:00');
|
||||
$schedule->call(new WarnDev)->dailyAt('16:00');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,4 +22,4 @@ class WarnDev extends Command
|
||||
|
||||
sendSMS('61929248', 'Warnings: '.$warnings->count());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@@ -44,7 +44,7 @@ class Handler extends ExceptionHandler
|
||||
warn(
|
||||
message: get_class($e),
|
||||
content: $e->getMessage(),
|
||||
where: $e->getFile() . ':' . $e->getLine(),
|
||||
where: $e->getFile().':'.$e->getLine(),
|
||||
notes: substr($e->getTraceAsString(), 0, 65000),
|
||||
);
|
||||
} catch (Throwable $ignored) {
|
||||
|
||||
@@ -390,7 +390,7 @@ function createHalkbankOrder($price = 123): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Warn brother
|
||||
*/
|
||||
function warn(string $message, string $content = '', string $where = '', string $notes = ''): void
|
||||
@@ -401,4 +401,4 @@ function warn(string $message, string $content = '', string $where = '', string
|
||||
'where' => $where,
|
||||
'notes' => $notes,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Category\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SelectedCategoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'is_visible' => $this->is_visible,
|
||||
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Category;
|
||||
|
||||
use App\Http\Controllers\Api\V1\Category\Resources\SelectedCategoryResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ecommerce\Product\Category\SelectedCategory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SelectedCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Selected Categories (index)
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$selectedCategories = SelectedCategory::query()
|
||||
->where('is_visible', true)
|
||||
->with(['categories' => function ($query) {
|
||||
$query->where('is_visible', true)->ordered()->with(['media']);
|
||||
}])
|
||||
->get();
|
||||
|
||||
return response()->json(SelectedCategoryResource::collection($selectedCategories));
|
||||
}
|
||||
|
||||
/**
|
||||
* Selected Categories (show)
|
||||
*/
|
||||
public function show(SelectedCategory $selectedCategory): JsonResponse
|
||||
{
|
||||
$selectedCategory->load('categories');
|
||||
|
||||
return response()->json(new SelectedCategoryResource($selectedCategory));
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class OrderPaymentController extends Controller
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return response()->rest(
|
||||
PaymentType::all(['id', 'name'])
|
||||
PaymentType::query()->where('is_enabled', true)->get(['id', 'name'])
|
||||
->map(fn ($paymentType) => [
|
||||
'id' => $paymentType->id,
|
||||
'name' => $paymentType->name,
|
||||
|
||||
@@ -15,6 +15,7 @@ class ProductMediaResource extends JsonResource
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'original' => $this->getUrl(),
|
||||
'thumbnail' => $this->getUrl('thumb400x400'),
|
||||
'images_400x400' => $this->getUrl('thumb400x400'),
|
||||
'images_800x800' => $this->getUrl('thumb800x800'),
|
||||
|
||||
@@ -111,7 +111,7 @@ class Channel extends Model implements HasMedia, Sortable
|
||||
{
|
||||
$this->addMediaConversion('thumb400x400')
|
||||
->fit(Manipulations::FIT_CONTAIN, 400, 400);
|
||||
|
||||
|
||||
$this->addMediaConversion('thumb800x800')
|
||||
->fit(Manipulations::FIT_CONTAIN, 800, 800);
|
||||
|
||||
|
||||
31
app/Models/Ecommerce/Product/Category/SelectedCategory.php
Normal file
31
app/Models/Ecommerce/Product/Category/SelectedCategory.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Category;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
class SelectedCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasTranslations;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'is_visible',
|
||||
];
|
||||
|
||||
public $translatable = ['name', 'description'];
|
||||
|
||||
protected $casts = [
|
||||
'is_visible' => 'boolean',
|
||||
];
|
||||
|
||||
public function categories(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Category::class, 'category_selected_category');
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Order;
|
||||
|
||||
use App\Models\Concerns\HasSchemalessAttributes;
|
||||
use App\Models\Ecommerce\Product\Order\Concerns\HasPayments;
|
||||
use App\Models\Ecommerce\Product\Order\Concerns\HasShipping;
|
||||
use App\Models\Ecommerce\Product\Order\Concerns\HasStatus;
|
||||
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
||||
use App\Models\Concerns\HasSchemalessAttributes;
|
||||
use App\Models\System\Settings\Location\Province;
|
||||
use App\Models\System\Settings\Payments\PaymentType;
|
||||
use App\Models\User;
|
||||
@@ -20,10 +20,10 @@ class Order extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasPayments;
|
||||
use HasSchemalessAttributes;
|
||||
use HasShipping;
|
||||
use HasStatus;
|
||||
use SoftDeletes;
|
||||
use HasSchemalessAttributes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Nova\Resources\Ecommerce\Product\Category;
|
||||
|
||||
use App\Models\Ecommerce\Product\Category\SelectedCategory as SelectedCategoryModel;
|
||||
use App\Nova\Resource;
|
||||
use Laravel\Nova\Fields\BelongsToMany;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Fields\Textarea;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
use Trin4ik\NovaSwitcher\NovaSwitcher;
|
||||
|
||||
class SelectedCategory extends Resource
|
||||
{
|
||||
/**
|
||||
* The model the resource corresponds to.
|
||||
*
|
||||
* @var class-string<SelectedCategoryModel>
|
||||
*/
|
||||
public static $model = SelectedCategoryModel::class;
|
||||
|
||||
/**
|
||||
* The single value that should be used to represent the resource when being displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $title = 'name';
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $search = [
|
||||
'id', 'name',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the displayable label of the resource.
|
||||
*/
|
||||
public static function label(): string
|
||||
{
|
||||
return __('Sections');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the displayable singular label of the resource.
|
||||
*/
|
||||
public static function singularLabel(): string
|
||||
{
|
||||
return __('Section');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields displayed by the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields(NovaRequest $request)
|
||||
{
|
||||
return [
|
||||
ID::make()->sortable(),
|
||||
|
||||
Text::make(__('Name'), 'name')
|
||||
->sortable()
|
||||
->translatable()
|
||||
->rules('required'),
|
||||
|
||||
Textarea::make(__('Description'), 'description')
|
||||
->translatable()
|
||||
->nullable(),
|
||||
|
||||
NovaSwitcher::make(__('Is Visible'), 'is_visible')
|
||||
->default(true),
|
||||
|
||||
BelongsToMany::make(__('Categories'), 'categories', Category::class),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cards available for the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cards(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filters available for the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filters(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lenses available for the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function lenses(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actions available for the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function actions(NovaRequest $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use App\Nova\Resources\Ecommerce\Payout\PayoutResource;
|
||||
use App\Nova\Resources\Ecommerce\Product\Attribute\Attribute;
|
||||
use App\Nova\Resources\Ecommerce\Product\Brand\Brand;
|
||||
use App\Nova\Resources\Ecommerce\Product\Category\Category;
|
||||
use App\Nova\Resources\Ecommerce\Product\Category\SelectedCategory;
|
||||
use App\Nova\Resources\Ecommerce\Product\Collection\Collection;
|
||||
use App\Nova\Resources\Ecommerce\Product\Coupon\Coupon;
|
||||
use App\Nova\Resources\Ecommerce\Product\Inventory\Inventory;
|
||||
@@ -158,6 +159,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
MenuItem::resource(Category::class),
|
||||
MenuItem::resource(Brand::class),
|
||||
MenuItem::resource(Attribute::class),
|
||||
MenuItem::resource(SelectedCategory::class),
|
||||
])->icon('color-swatch'),
|
||||
])->icon('shopping-bag')->collapsedByDefault(),
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Repositories\Ecommerce\Product\Category;
|
||||
|
||||
use App\Models\Ecommerce\Product\Category\Category;
|
||||
use App\Repositories\System\Cache\CacheRepository;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CategoryRepository
|
||||
|
||||
@@ -52,10 +52,10 @@ class CreateOrderService
|
||||
'stock' => $stock,
|
||||
]);
|
||||
} else {
|
||||
warn('Product has no inventory record', json_encode([
|
||||
'product_id' => $cart->product_id,
|
||||
'order_id' => $order->id,
|
||||
]));
|
||||
warn('Product has no inventory record', json_encode([
|
||||
'product_id' => $cart->product_id,
|
||||
'order_id' => $order->id,
|
||||
]));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Spatie\MediaLibrary\Support\FileNamer\FileNamer;
|
||||
use Spatie\MediaLibrary\Conversions\Conversion;
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\MediaLibrary\Conversions\Conversion;
|
||||
use Spatie\MediaLibrary\Support\FileNamer\FileNamer;
|
||||
|
||||
class ShortFileNamer extends FileNamer
|
||||
{
|
||||
@@ -15,9 +16,6 @@ class ShortFileNamer extends FileNamer
|
||||
return Str::random(10);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function conversionFileName(string $fileName, Conversion $conversion): string
|
||||
{
|
||||
return $conversion->getName();
|
||||
@@ -27,4 +25,4 @@ class ShortFileNamer extends FileNamer
|
||||
{
|
||||
return 'res';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user