Compare commits
2 Commits
31b65eb676
...
67bc9e6cb4
| Author | SHA1 | Date | |
|---|---|---|---|
| 67bc9e6cb4 | |||
| 4125d8353d |
@@ -17,7 +17,7 @@ class BrandController extends Controller
|
|||||||
public function index(Tenant $tenant): JsonResponse
|
public function index(Tenant $tenant): JsonResponse
|
||||||
{
|
{
|
||||||
return BrandResource::collection(
|
return BrandResource::collection(
|
||||||
Brand::query()->where('tenant_codigo', $tenant->codigo)->orderByDesc('id')->get()
|
Brand::query()->where('tenant_codigo', $tenant->codigo)->orderByDesc('id')->paginateFromRequest()
|
||||||
)->response();
|
)->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class CategoryController extends Controller
|
|||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->with(['parent', 'subCategories', 'tenant'])
|
->with(['parent', 'subCategories', 'tenant'])
|
||||||
->orderByDesc('id')
|
->orderByDesc('id')
|
||||||
->get()
|
->paginateFromRequest()
|
||||||
)->response();
|
)->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class ProductAttributeController extends Controller
|
|||||||
->with('options')
|
->with('options')
|
||||||
->latest();
|
->latest();
|
||||||
|
|
||||||
return ProductAttributeResource::collection($query->get())->response();
|
return ProductAttributeResource::collection($query->paginateFromRequest())->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(StoreProductAttributeRequest $request, Tenant $tenant): JsonResponse
|
public function store(StoreProductAttributeRequest $request, Tenant $tenant): JsonResponse
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class ProductController extends Controller
|
|||||||
public function index(Tenant $tenant): JsonResponse
|
public function index(Tenant $tenant): JsonResponse
|
||||||
{
|
{
|
||||||
return ProductResource::collection(
|
return ProductResource::collection(
|
||||||
Product::query()->where('tenant_codigo', $tenant->codigo)->latest()->get()
|
Product::query()->where('tenant_codigo', $tenant->codigo)->latest()->paginateFromRequest()
|
||||||
)->response();
|
)->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class ProductVariantController extends Controller
|
|||||||
->with(['product', 'definitions.attribute'])
|
->with(['product', 'definitions.attribute'])
|
||||||
->latest();
|
->latest();
|
||||||
|
|
||||||
return ProductVariantResource::collection($query->get())->response();
|
return ProductVariantResource::collection($query->paginateFromRequest())->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(StoreProductVariantRequest $request, Tenant $tenant): JsonResponse
|
public function store(StoreProductVariantRequest $request, Tenant $tenant): JsonResponse
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class PurchaseController extends Controller
|
|||||||
->where('tenant_codigo', $tenant->codigo)
|
->where('tenant_codigo', $tenant->codigo)
|
||||||
->where('user_id', $request->user()->id)
|
->where('user_id', $request->user()->id)
|
||||||
->latest()
|
->latest()
|
||||||
->get()
|
->paginateFromRequest()
|
||||||
)->response();
|
)->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class TenantController extends Controller
|
|||||||
|
|
||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
return TenantResource::collection(Tenant::query()->with(['headerLogo', 'footerLogo'])->latest()->get())->response();
|
return TenantResource::collection(Tenant::query()->with(['headerLogo', 'footerLogo'])->latest()->paginateFromRequest())->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(StoreTenantRequest $request): JsonResponse
|
public function store(StoreTenantRequest $request): JsonResponse
|
||||||
|
|||||||
@@ -19,6 +19,22 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
//
|
\Illuminate\Database\Eloquent\Builder::macro('paginateFromRequest', function (int $defaultPerPage = 15, int $maxPerPage = 100, ?int $page = null) {
|
||||||
|
/** @var \Illuminate\Database\Eloquent\Builder $this */
|
||||||
|
$perPage = (int) request()->query('per_page', $defaultPerPage);
|
||||||
|
$page = $page ?? (int) request()->query('page', 1);
|
||||||
|
|
||||||
|
if ($perPage <= 0) {
|
||||||
|
$perPage = $defaultPerPage;
|
||||||
|
}
|
||||||
|
if ($perPage > $maxPerPage) {
|
||||||
|
$perPage = $maxPerPage;
|
||||||
|
}
|
||||||
|
if ($page <= 0) {
|
||||||
|
$page = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->paginate(perPage: $perPage, page: $page);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
'name' => 'Test User',
|
'name' => 'Test User',
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->call(TenantSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
82
database/seeders/TenantSeeder.php
Normal file
82
database/seeders/TenantSeeder.php
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Tenant\Services\TenantService;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
|
||||||
|
class TenantSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function __construct(protected TenantService $tenantService)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
// Check if tenant 'sonder' already exists and delete it to prevent duplicates
|
||||||
|
$existing = Tenant::query()->where('codigo', 'sonder')->first();
|
||||||
|
if ($existing) {
|
||||||
|
$attachmentService = app(\App\Domains\Attachable\Services\AttachmentService::class);
|
||||||
|
if ($existing->headerLogo) {
|
||||||
|
try {
|
||||||
|
$attachmentService->delete($existing->headerLogo);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// Ignore exception on cleanup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($existing->footerLogo && $existing->footer_logo_id !== $existing->header_logo_id) {
|
||||||
|
try {
|
||||||
|
$attachmentService->delete($existing->footerLogo);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// Ignore exception on cleanup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$existing->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if domain 'localhost' is already in use by another tenant and delete it
|
||||||
|
$existingDomain = Tenant::query()->where('dominio', 'localhost')->first();
|
||||||
|
if ($existingDomain) {
|
||||||
|
$existingDomain->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$imagePath = public_path('images/sonder.png');
|
||||||
|
|
||||||
|
if (! file_exists($imagePath)) {
|
||||||
|
throw new \RuntimeException("Image not found at path: {$imagePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$headerLogo = new UploadedFile(
|
||||||
|
$imagePath,
|
||||||
|
'sonder.png',
|
||||||
|
'image/png',
|
||||||
|
null,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$footerLogo = new UploadedFile(
|
||||||
|
$imagePath,
|
||||||
|
'sonder.png',
|
||||||
|
'image/png',
|
||||||
|
null,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->tenantService->create([
|
||||||
|
'codigo' => 'sonder',
|
||||||
|
'nombre' => 'Sonder',
|
||||||
|
'dominio' => 'localhost',
|
||||||
|
'primary_color' => '#6376F3',
|
||||||
|
'secondary_color' => '#A0A0A0',
|
||||||
|
'danger_color' => '#FF8888',
|
||||||
|
'header_footer_bg_color' => '#313131',
|
||||||
|
'header_logo' => $headerLogo,
|
||||||
|
'footer_logo' => $footerLogo,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
public/images/sonder.png
Normal file
BIN
public/images/sonder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Reference in New Issue
Block a user