Addec crud entries for a company / companies
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Modules\Company\Http\Controllers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Company\Models\Company;
|
||||
|
||||
class CompanyController extends Controller
|
||||
@@ -38,4 +39,56 @@ class CompanyController extends Controller
|
||||
|
||||
return back()->with('status', 'Company created.');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
|
||||
return view('company::create', [
|
||||
|
||||
'company' => new Company,
|
||||
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function show(Company $company)
|
||||
{
|
||||
return view('company::show', [
|
||||
'company' => $company,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Company $company)
|
||||
{
|
||||
return view('company::edit', [
|
||||
'company' => $company,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Company $company)
|
||||
{
|
||||
$company->update($this->validated($request, $company));
|
||||
|
||||
return redirect()
|
||||
->route('platform.companies.show', $company)
|
||||
->with('status', 'Company updated.');
|
||||
}
|
||||
|
||||
public function destroy(Company $company)
|
||||
{
|
||||
$company->delete();
|
||||
|
||||
return redirect()
|
||||
->route('platform.companies.index')
|
||||
->with('status', 'Company deleted.');
|
||||
}
|
||||
|
||||
private function validated(Request $request, ?Company $company = null): array
|
||||
{
|
||||
return $request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'billing_email' => ['required', 'email', 'max:255'],
|
||||
'status' => ['required', Rule::in(['active', 'inactive'])],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ class RouteServiceProvider extends ServiceProvider
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $moduleNamespace = 'Modules\Company\Http\Controllers';
|
||||
protected $moduleNamespace = '';
|
||||
// this must be blank for resource routes !!
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
{{-- Modules/Company/resources/views/companies/_form.blade.php --}}
|
||||
|
||||
@csrf
|
||||
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Name</label>
|
||||
<input
|
||||
name="name"
|
||||
value="{{ old('name', $company->name) }}"
|
||||
class="mt-1 w-full rounded-lg border-gray-300"
|
||||
required
|
||||
>
|
||||
@error('name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Billing email</label>
|
||||
<input
|
||||
type="email"
|
||||
name="billing_email"
|
||||
value="{{ old('billing_email', $company->billing_email) }}"
|
||||
class="mt-1 w-full rounded-lg border-gray-300"
|
||||
required
|
||||
>
|
||||
@error('billing_email') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Status</label>
|
||||
<select name="status" class="mt-1 w-full rounded-lg border-gray-300" required>
|
||||
<option value="active" @selected(old('status', $company->status) === 'active')>Active</option>
|
||||
<option value="inactive" @selected(old('status', $company->status) === 'inactive')>Inactive</option>
|
||||
</select>
|
||||
@error('status') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<button class="rounded-lg bg-blue-600 px-4 py-2 text-white">
|
||||
Save company
|
||||
</button>
|
||||
|
||||
<a href="{{ route('platform.companies.index') }}" class="text-sm text-gray-600">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,9 @@
|
||||
{{-- Modules/Company/resources/views/companies/create.blade.php --}}
|
||||
|
||||
<x-layouts::app :title="__('Create Company')">
|
||||
<x-wms.page-hero title="Create company" subtitle="Add a new tenant company." />
|
||||
|
||||
<form method="POST" action="{{ route('platform.companies.store') }}" class="max-w-3xl">
|
||||
@include('company::companies._form')
|
||||
</form>
|
||||
</x-layouts::app>
|
||||
@@ -0,0 +1,17 @@
|
||||
<x-layouts::app :title="__('Edit Company')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero
|
||||
eyebrow="Platform Administration"
|
||||
title="Edit company"
|
||||
description="Update tenant company details."
|
||||
icon="fa-solid fa-building"
|
||||
/>
|
||||
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<form method="POST" action="{{ route('platform.companies.update', $company) }}" class="space-y-5">
|
||||
@method('PUT')
|
||||
@include('company::_form')
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -1,49 +1,114 @@
|
||||
<x-layouts::app :title="__('Companies')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero eyebrow="Platform Administration" title="Companies"
|
||||
<x-wms.page-hero
|
||||
eyebrow="Platform Administration"
|
||||
title="Companies"
|
||||
description="Manage tenant companies and keep every company’s users, warehouses and records isolated."
|
||||
icon="fa-solid fa-building" />
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<h2 class="text-lg font-bold text-zinc-900 dark:text-white">Create company</h2>
|
||||
<form method="POST" action="{{ route('platform.companies.store') }}" class="mt-5 grid gap-4 md:grid-cols-4">
|
||||
@csrf
|
||||
<input name="name" placeholder="Company name"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950" required>
|
||||
<input name="billing_email" placeholder="billing@example.com"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950">
|
||||
<select name="status" class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950">
|
||||
<option value="active">Active</option>
|
||||
<option value="suspended">Suspended</option>
|
||||
</select>
|
||||
<button
|
||||
class="rounded-xl bg-zinc-900 px-4 py-2 font-semibold text-white dark:bg-white dark:text-zinc-900">Create</button>
|
||||
</form>
|
||||
icon="fa-solid fa-building"
|
||||
/>
|
||||
|
||||
<div class="flex justify-end">
|
||||
<a
|
||||
href="{{ route('platform.companies.create') }}"
|
||||
class="rounded-xl bg-zinc-900 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-zinc-700 dark:bg-white dark:text-zinc-900"
|
||||
>
|
||||
Create company
|
||||
</a>
|
||||
</div>
|
||||
<div
|
||||
class="overflow-x-auto rounded-2xl bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
|
||||
<div class="overflow-x-auto rounded-2xl bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<table class="min-w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b">
|
||||
<th class="p-4 text-left">Name</th>
|
||||
<th class="p-4 text-left">Users</th>
|
||||
<th class="p-4 text-left">Warehouses</th>
|
||||
<th class="p-4 text-left">Licences</th>
|
||||
<th class="p-4 text-left">Status</th>
|
||||
</tr>
|
||||
<tr class="border-b border-zinc-200 dark:border-zinc-800">
|
||||
<th class="p-4 text-left">Name</th>
|
||||
<th class="p-4 text-left">Users</th>
|
||||
<th class="p-4 text-left">Warehouses</th>
|
||||
<th class="p-4 text-left">Licences</th>
|
||||
<th class="p-4 text-left">Status</th>
|
||||
<th class="p-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($companies as $company)
|
||||
<tr class="border-b border-zinc-100 dark:border-zinc-800">
|
||||
<td class="p-4 font-semibold">{{ $company->name }}</td>
|
||||
<td class="p-4">{{ $company->users_count }}</td>
|
||||
<td class="p-4">{{ $company->warehouses_count }}</td>
|
||||
<td class="p-4">{{ $company->license_keys_count }}</td>
|
||||
<td class="p-4">{{ $company->is_system_company ? 'System' : $company->status }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@forelse ($companies as $company)
|
||||
<tr class="border-b border-zinc-100 dark:border-zinc-800">
|
||||
<td class="p-4 font-semibold text-zinc-900 dark:text-white">
|
||||
{{ $company->name }}
|
||||
</td>
|
||||
|
||||
<td class="p-4 text-zinc-700 dark:text-zinc-300">
|
||||
{{ $company->users_count }}
|
||||
</td>
|
||||
|
||||
<td class="p-4 text-zinc-700 dark:text-zinc-300">
|
||||
{{ $company->warehouses_count }}
|
||||
</td>
|
||||
|
||||
<td class="p-4 text-zinc-700 dark:text-zinc-300">
|
||||
{{ $company->license_keys_count }}
|
||||
</td>
|
||||
|
||||
<td class="p-4">
|
||||
<span class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold
|
||||
@if ($company->is_system_company)
|
||||
bg-blue-100 text-blue-700 dark:bg-blue-950 dark:text-blue-300
|
||||
@elseif ($company->status === 'active')
|
||||
bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-300
|
||||
@else
|
||||
bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300
|
||||
@endif
|
||||
">
|
||||
{{ $company->is_system_company ? 'System' : ucfirst($company->status) }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td class="p-4">
|
||||
<div class="flex justify-end gap-2">
|
||||
<a
|
||||
href="{{ route('platform.companies.show', $company) }}"
|
||||
class="rounded-lg border border-zinc-300 px-3 py-1.5 text-xs font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800"
|
||||
>
|
||||
View
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="{{ route('platform.companies.edit', $company) }}"
|
||||
class="rounded-lg bg-blue-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-blue-700"
|
||||
>
|
||||
Edit
|
||||
</a>
|
||||
|
||||
@unless ($company->is_system_company)
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('platform.companies.destroy', $company) }}"
|
||||
onsubmit="return confirm('Delete this company? This cannot be undone.');"
|
||||
>
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="rounded-lg bg-red-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-red-700"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
@endunless
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="6" class="p-8 text-center text-zinc-500 dark:text-zinc-400">
|
||||
No companies found.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{{ $companies->links() }}
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<x-layouts::app :title="$company->name">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero
|
||||
eyebrow="Platform Administration"
|
||||
:title="$company->name"
|
||||
description="Company details and administration."
|
||||
icon="fa-solid fa-building"
|
||||
/>
|
||||
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<dl class="grid gap-5 md:grid-cols-2">
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Billing email</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->billing_email ?? '—' }}</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Status</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">
|
||||
{{ $company->is_system_company ? 'System' : ucfirst($company->status) }}
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Timezone</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->timezone }}</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Slug</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->slug }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<div class="mt-6 flex gap-3">
|
||||
<a
|
||||
href="{{ route('platform.companies.edit', $company) }}"
|
||||
class="rounded-xl bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-700"
|
||||
>
|
||||
Edit
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="{{ route('platform.companies.index') }}"
|
||||
class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800"
|
||||
>
|
||||
Back
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -13,10 +13,9 @@
|
||||
|
||||
use Modules\Company\Http\Controllers\CompanyController;
|
||||
|
||||
Route::middleware(['auth', 'verified', 'tenant.assigned', 'platform.admin'])
|
||||
Route::middleware(['web', 'auth', 'verified', 'tenant.assigned', 'platform.admin'])
|
||||
->prefix('admin')
|
||||
->name('platform.')
|
||||
->group(function (): void {
|
||||
Route::get('/companies', [CompanyController::class, 'index'])->name('companies.index');
|
||||
Route::post('/companies', [CompanyController::class, 'store'])->name('companies.store');
|
||||
->group(function () {
|
||||
Route::resource('companies', CompanyController::class);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user