From 1453f77a0d7d95ade3dc3896165b148bfe6879da Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:11:22 +0000 Subject: [PATCH] Add Client Management Functionality to Billing Application --- app/Http/Controllers/ClientController.php | 79 +++++++++++++++++++ app/Models/Client.php | 28 +++++++ ...2024_01_20_000000_create_clients_table.php | 30 +++++++ resources/views/clients/index.blade.php | 77 ++++++++++++++++++ routes/web.php | 5 ++ 5 files changed, 219 insertions(+) create mode 100644 app/Http/Controllers/ClientController.php create mode 100644 app/Models/Client.php create mode 100644 database/migrations/2024_01_20_000000_create_clients_table.php create mode 100644 resources/views/clients/index.blade.php diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php new file mode 100644 index 00000000..f1f223e4 --- /dev/null +++ b/app/Http/Controllers/ClientController.php @@ -0,0 +1,79 @@ + + +search) { + $query->where(function($q) use ($request) { + $q->where('name', 'like', "%{$request->search}%") + ->orWhere('email', 'like', "%{$request->search}%") + ->orWhere('company', 'like', "%{$request->search}%"); + }); + } + + if ($request->status) { + $query->where('status', $request->status); + } + + $clients = $query->paginate(10); + return view('clients.index', compact('clients')); + } + + public function create() + { + return view('clients.create'); + } + + public function store(Request $request) + { + $validated = $request->validate([ + 'name' => 'required|string|max:255', + 'email' => 'required|email|unique:clients', + 'phone' => 'nullable|string|max:20', + 'company' => 'nullable|string|max:255', + 'address' => 'nullable|string', + 'notes' => 'nullable|string', + 'status' => 'required|in:active,inactive', + ]); + + Client::create($validated); + return redirect()->route('clients.index')->with('success', 'Client created successfully'); + } + + public function edit(Client $client) + { + return view('clients.edit', compact('client')); + } + + public function update(Request $request, Client $client) + { + $validated = $request->validate([ + 'name' => 'required|string|max:255', + 'email' => 'required|email|unique:clients,email,'.$client->id, + 'phone' => 'nullable|string|max:20', + 'company' => 'nullable|string|max:255', + 'address' => 'nullable|string', + 'notes' => 'nullable|string', + 'status' => 'required|in:active,inactive', + ]); + + $client->update($validated); + return redirect()->route('clients.index')->with('success', 'Client updated successfully'); + } + + public function destroy(Client $client) + { + $client->delete(); + return redirect()->route('clients.index')->with('success', 'Client deleted successfully'); + } +} \ No newline at end of file diff --git a/app/Models/Client.php b/app/Models/Client.php new file mode 100644 index 00000000..acddc3fc --- /dev/null +++ b/app/Models/Client.php @@ -0,0 +1,28 @@ + + + 'datetime', + 'updated_at' => 'datetime', + ]; +} \ No newline at end of file diff --git a/database/migrations/2024_01_20_000000_create_clients_table.php b/database/migrations/2024_01_20_000000_create_clients_table.php new file mode 100644 index 00000000..80941781 --- /dev/null +++ b/database/migrations/2024_01_20_000000_create_clients_table.php @@ -0,0 +1,30 @@ + + +id(); + $table->string('name'); + $table->string('email')->unique(); + $table->string('phone')->nullable(); + $table->string('company')->nullable(); + $table->text('address')->nullable(); + $table->text('notes')->nullable(); + $table->enum('status', ['active', 'inactive'])->default('active'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('clients'); + } +}; \ No newline at end of file diff --git a/resources/views/clients/index.blade.php b/resources/views/clients/index.blade.php new file mode 100644 index 00000000..f998f5fc --- /dev/null +++ b/resources/views/clients/index.blade.php @@ -0,0 +1,77 @@ + + + + +
+

+ {{ __('Clients') }} +

+ + Add Client + +
+
+ +
+
+
+ +
+
+ + + +
+
+ + + + + + + + + + + + + + @foreach($clients as $client) + + + + + + + + @endforeach + +
NameEmailCompanyStatusActions
{{ $client->name }}{{ $client->email }}{{ $client->company }} + + {{ $client->status }} + + + Edit +
+ @csrf + @method('DELETE') + +
+
+ +
+ {{ $clients->links() }} +
+
+
+
+
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 5de5c635..b43c9bc9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ use Illuminate\Session\Middleware\AuthenticateSession; use Illuminate\Support\Facades\Route; use Laravel\Jetstream\Http\Controllers\TeamInvitationController; +use App\Http\Controllers\ClientController; /* |-------------------------------------------------------------------------- @@ -17,6 +18,10 @@ Route::get('/', fn () => view('welcome')); +Route::middleware(['auth:sanctum', 'verified'])->group(function () { + Route::resource('clients', ClientController::class); +}); + // Route::redirect('/login', '/app/login')->name('login'); // Route::redirect('/register', '/app/register')->name('register');