Country / Company updates
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('companies', function (Blueprint $table): void {
|
||||
$table->foreignId('country_id')
|
||||
->nullable()
|
||||
->after('billing_email')
|
||||
->constrained('countries')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('companies', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('country_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -18,10 +18,11 @@ class CompanyController extends Controller
|
||||
{
|
||||
return view('company::index', [
|
||||
'companies' => Company::query()
|
||||
->with(['address.country'])
|
||||
->with(['address.country', 'country'])
|
||||
->withCount(['users', 'warehouses', 'licenseKeys', 'divisions'])
|
||||
->latest('id')
|
||||
->paginate(20),
|
||||
'countries' => $this->countries(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ class CompanyController extends Controller
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
]),
|
||||
'countries' => $this->countries(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -83,7 +85,8 @@ class CompanyController extends Controller
|
||||
public function edit(Company $company)
|
||||
{
|
||||
return view('company::edit', [
|
||||
'company' => $company,
|
||||
'company' => $company->loadMissing(['address.country', 'country']),
|
||||
'countries' => $this->countries(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -119,12 +122,20 @@ class CompanyController extends Controller
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'billing_email' => ['nullable', 'email', 'max:255'],
|
||||
'status' => ['required', Rule::in(['active', 'suspended', 'inactive'])],
|
||||
'timezone' => ['nullable', 'string', 'max:64'],
|
||||
'country_id' => ['nullable', Rule::exists('countries', 'id')->where('is_active', true)],
|
||||
]);
|
||||
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
$data['timezone'] = $data['timezone'] ?? ($company?->timezone ?: 'Europe/London');
|
||||
$data['timezone'] = $company?->timezone ?: 'Europe/London';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function countries()
|
||||
{
|
||||
return Country::query()
|
||||
->active()
|
||||
->ordered()
|
||||
->get(['id', 'alpha2', 'name', 'display_name', 'common_name', 'sort_order']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ namespace Modules\Company\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Platform\app\Models\LicenseKey;
|
||||
use Modules\Platform\app\Models\Payment;
|
||||
use Modules\Countries\Models\Country;
|
||||
use Modules\Warehouse\app\Models\Warehouse;
|
||||
|
||||
class Company extends Model
|
||||
@@ -18,7 +20,7 @@ class Company extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'uuid', 'name', 'slug', 'status', 'timezone', 'settings',
|
||||
'is_system_company', 'stripe_customer_id', 'billing_email',
|
||||
'is_system_company', 'stripe_customer_id', 'billing_email', 'country_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -37,6 +39,12 @@ class Company extends Model
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function country(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Country::class);
|
||||
}
|
||||
|
||||
public function address(): MorphOne
|
||||
{
|
||||
return $this->morphOne(CompanyAddress::class, 'addressable');
|
||||
|
||||
@@ -47,15 +47,23 @@
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="timezone" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Timezone</label>
|
||||
<input
|
||||
id="timezone"
|
||||
name="timezone"
|
||||
value="{{ old('timezone', $company->timezone ?? 'Europe/London') }}"
|
||||
<div class="wms-select2-field">
|
||||
<label for="country_id" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Country</label>
|
||||
<select
|
||||
id="country_id"
|
||||
name="country_id"
|
||||
data-wms-select2
|
||||
data-placeholder="Search and select a country"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
|
||||
>
|
||||
@error('timezone')
|
||||
<option value="">Search and select a country</option>
|
||||
@foreach ($countries as $country)
|
||||
<option value="{{ $country->id }}" @selected((int) old('country_id', $company->country_id ?? $company->address?->country_id) === $country->id)>
|
||||
{{ $country->effective_name ?? $country->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('country_id')
|
||||
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
@@ -55,12 +55,16 @@
|
||||
<option value="inactive" @selected(old('status') === 'inactive')>Inactive</option>
|
||||
</select>
|
||||
|
||||
<input
|
||||
name="timezone"
|
||||
value="{{ old('timezone', 'Europe/London') }}"
|
||||
placeholder="Europe/London"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
|
||||
>
|
||||
<div class="wms-select2-field">
|
||||
<select name="country_id" data-wms-select2 data-placeholder="Search country" class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white">
|
||||
<option value="">Search country</option>
|
||||
@foreach ($countries as $country)
|
||||
<option value="{{ $country->id }}" @selected((int) old('country_id') === $country->id)>
|
||||
{{ $country->effective_name ?? $country->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button class="rounded-xl bg-zinc-900 px-4 py-2 font-semibold text-white dark:bg-white dark:text-zinc-900">
|
||||
Create
|
||||
|
||||
Reference in New Issue
Block a user