# HG changeset patch # User luka # Date 1756428940 14400 # Node ID 90296614b7e2405e0f6563370baebe48b0a73e65 # Parent 8971e685366ba442a80f63302ed01aa8ffbc6834 Adding in the base for the clients table diff -r 8971e685366b -r 90296614b7e2 app/Http/Controllers/ClientController.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/Http/Controllers/ClientController.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,129 @@ +validated(); + $data = []; + $data['items'] = Client::get_data($validated); + $data = array_merge($data, Client::load_index()); + + return view('clients.index', $data); + } + + public function get_data() + { + $data = []; + $data['records'] = Client::get_data([]); + $data['total_records'] = count($data['records']); + + return $data; + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\View\View + */ + public function create() + { + $data = []; + $data = array_merge($data, Client::load_create()); + + return view('clients.create_edit', $data); + } + + /** + * Store a newly created resource in storage. + * + * @return \Illuminate\Http\RedirectResponse + */ + public function store(StoreClientRequest $request) + { + $validated = $request->validated(); + + Client::create($validated); + + return redirect()->route('clients.index'); + } + + /** + * Display the specified resource. + * + * @return \Illuminate\View\View + */ + public function show(Client $client) + { + $data = []; + $data['item'] = $client; + $data['fields'] = (new Client)->getFillable(); + + return view('clients.show', $data); + } + + /** + * Returns the resource in JSON format. + * + * @param ModelType $modelVariable + * @return string + */ + public function load(Client $client) + { + return $client->toJson(); + } + + /** + * Show the form for editing the specified resource. + * + * @return \Illuminate\View\View + */ + public function edit(Client $client) + { + $data = []; + $data['item'] = $client; + + // Load data for relationships + $data = array_merge($data, Client::load_edit()); + + return view('clients.create_edit', $data); + } + + /** + * Update the specified resource in storage. + * + * @return \Illuminate\Http\RedirectResponse + */ + public function update(UpdateClientRequest $request, Client $client) + { + $validated = $request->validated(); + + $client->update($validated); + + return redirect()->route('clients.index'); + } + + /** + * Remove the specified resource from storage. + * + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(Client $client) + { + $client->delete(); + + return redirect()->route('clients.index'); + } +} diff -r 8971e685366b -r 90296614b7e2 app/Http/Requests/Client/FilterClientRequest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/Http/Requests/Client/FilterClientRequest.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,33 @@ + + */ + public function rules(): array + { + return [ + 'name' => 'nullable', + 'email' => 'nullable', + 'phone_number' => 'nullable', + 'address' => 'nullable', + 'notes' => 'nullable', + + ]; + } +} diff -r 8971e685366b -r 90296614b7e2 app/Http/Requests/Client/StoreClientRequest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/Http/Requests/Client/StoreClientRequest.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,33 @@ + + */ + public function rules(): array + { + return [ + 'name' => 'nullable', + 'email' => 'nullable', + 'phone_number' => 'nullable', + 'address' => 'nullable', + 'notes' => 'nullable', + + ]; + } +} diff -r 8971e685366b -r 90296614b7e2 app/Http/Requests/Client/UpdateClientRequest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/Http/Requests/Client/UpdateClientRequest.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,33 @@ + + */ + public function rules(): array + { + return [ + 'name' => 'nullable', + 'email' => 'nullable', + 'phone_number' => 'nullable', + 'address' => 'nullable', + 'notes' => 'nullable', + + ]; + } +} diff -r 8971e685366b -r 90296614b7e2 app/Models/Client.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/Models/Client.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,126 @@ + [ + 'column_name' => 'name', + 'table' => 'clients', + 'display' => 'Name', + 'type' => 'value', + ], + 'email' => [ + 'column_name' => 'email', + 'table' => 'clients', + 'display' => 'Email', + 'type' => 'value', + ], + 'phone_number' => [ + 'column_name' => 'phone_number', + 'table' => 'clients', + 'display' => 'Phone Number', + 'type' => 'value', + ], + 'address' => [ + 'column_name' => 'address', + 'table' => 'clients', + 'display' => 'Address', + 'type' => 'value', + ], + 'notes' => [ + 'column_name' => 'notes', + 'table' => 'clients', + 'display' => 'Notes', + 'type' => 'value', + ], + + ]; + + public static function get_filters() + { + return static::filters; + } + + // relations + + // BelongsTo + + // HasMany + + // HasManyThrough + + /** + * Load the default relations for the model. + * + * @return $this + */ + public function load_relations() + { + foreach ($this->default_relations as $relation) { + $this->load($relation); + } + + return $this; + } + + /** + * Retrieve a query builder instance with default relations loaded. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function data_query() + { + return parent::data_query(); + } + + /** + * Retrieve a query builder instance with default relations loaded. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function get_data(array $validated = []) + { + return parent::get_data($validated); + } +} diff -r 8971e685366b -r 90296614b7e2 database/migrations/2025_08_29_004806_create_clients_table.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/database/migrations/2025_08_29_004806_create_clients_table.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,31 @@ +baseColumns(); + $table->string('name'); + $table->string('email')->nullable(); + $table->string('phone_number')->nullable(); + $table->string('address')->nullable(); + $table->text('notes')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('clients'); + } +}; diff -r 8971e685366b -r 90296614b7e2 resources/views/clients/create_edit.blade.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/views/clients/create_edit.blade.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,64 @@ + + + + {{ isset($item) ? 'Edit' : 'Create' }} {{ ucfirst('client') }} + + + + + + + + @csrf + @if (isset($item)) + @method('PUT') + @endif + + + + + + + + + + + + + + Back + + {{ isset($item) ? 'Update' : 'Create' }} + + + + + + + diff -r 8971e685366b -r 90296614b7e2 resources/views/clients/index.blade.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/views/clients/index.blade.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,112 @@ + + + + All {{ Str::plural(ucfirst('client')) }} + + + + + + + + + + New {{ ucfirst('client') }} + + + + + + + + @include('includes.ServerTable') + @pushOnce('scripts') + + @endpushOnce + + diff -r 8971e685366b -r 90296614b7e2 resources/views/clients/show.blade.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/views/clients/show.blade.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,26 @@ + + + + {{ ucfirst('client') }} Details + + + + + + + + @foreach($fields as $field) + + {{ ucfirst($field) }}: + {{ $item->$field }} + + @endforeach + + + Edit + Back + + + + + diff -r 8971e685366b -r 90296614b7e2 routes/resources/Client.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/routes/resources/Client.php Thu Aug 28 20:55:40 2025 -0400 @@ -0,0 +1,21 @@ +middleware(['web', 'auth']) + ->prefix('clients') + ->as('clients.') + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/get_data', 'get_data')->name('get_data'); + Route::get('/create', 'create')->name('create'); + Route::get('/{client}/edit', 'edit')->name('edit'); + Route::get('/{client}', 'show')->name('show'); + Route::get('/{client}/load', 'load')->name('load'); + + Route::post('/store', 'store')->name('store'); + Route::put('/udpate/{client}', 'update')->name('update'); + Route::delete('/destroy/{client}', 'destroy')->name('destroy'); + });