Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product group curd #21

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/Http/Controllers/ProductGroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Http\Controllers;

use App\Models;
use Illuminate\Http\Request;

class ProductGroupController extends Controller
{
public function index()
{
$productGroups = Models\ProductGroup::paginate(12);
return view('productGroups.index', compact('productGroups'));
}

public function create()
{
return view('productGroups.create');
}

public function store(Request $request)
{
// TODO validate request
$validatedData = $request->validate([
'code' => 'required|unique:product_groups,code|regex:/^\d{3}$/',
'name' => 'required|max:20|string|regex:/^[\w\d\s]*$/u'
]);

Models\ProductGroup::create($validatedData);

return redirect()->route('product-groups.index')->with('success', 'Product group created successfully.');
}

public function edit(Models\ProductGroup $productGroup)
{
return view('productGroups.edit', compact('productGroup'));
}

public function update(Request $request, Models\ProductGroup $productGroup)
{
// TODO validate request
$validatedData = $request->validate([
'code' => 'required|unique:product_groups,code,'.$productGroup->id.',|regex:/^\d{3}$/',
'name' => 'required|max:20|string|regex:/^[\w\d\s]*$/u'
]);

$productGroup->update($validatedData);

return redirect()->route('product-groups.index')->with('success', 'Product group updated successfully.');
}

public function destroy(Models\ProductGroup $productGroup)
{
$productGroup->delete();

return redirect()->route('product-groups.index')->with('success', 'Product group deleted successfully.');
}

}
2 changes: 2 additions & 0 deletions app/Models/ProductGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ProductGroup extends Model
'sellId',
];

public $timestamps = false;

// Define relationships with other models (e.g., Subject)

public function buySubject()
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/app-layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<x-header/>

<main>
<main class="max-w-5xl mx-auto py-12">
{{ $slot }}
</main>

Expand Down
1 change: 1 addition & 0 deletions resources/views/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<li><a href="{{ route('subjects.index') }}" class="hover:text-gray-500">Subjects</a></li>
<li><a href="{{ route('transactions.index') }}" class="hover:text-gray-500">Transactions</a></li>
<li><a href="{{ route('products.index') }}" class="hover:text-gray-500">Products</a></li>
<li><a href="{{ route('product-groups.index') }}" class="hover:text-gray-500">Product Groups</a></li>
<li><a href="{{ route('customers.index') }}" class="hover:text-gray-500">Customers</a></li>
<li><a href="{{ route('customer-groups.index') }}" class="hover:text-gray-500">Customer Groups</a></li>
<li><a href="{{ route('bank-accounts.index') }}" class="hover:text-gray-500">Bank Accounts</a></li>
Expand Down
1 change: 1 addition & 0 deletions resources/views/daisyui.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="alert alert-success alert-error alert-warning alert-info"></div>
21 changes: 21 additions & 0 deletions resources/views/productGroups/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Create Product Group') }}
</h2>
</x-slot>

<div class="card bg-base-100 shadow-xl">
<form action="{{ route('product-groups.store') }}" method="POST">
@csrf
<div class="card-body">
<h2 class="card-title">{{ __('Add product group') }}</h2>
<x-show-message-bags/>
@include('productGroups.form')
<div class="card-actions justify-end">
<button type="submit" class="btn btn-primary">{{ __('Create') }}</button>
</div>
</div>
</form>
</div>
</x-app-layout>
22 changes: 22 additions & 0 deletions resources/views/productGroups/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Edit Product Groups') }}
</h2>
</x-slot>

<div class="card bg-base-100 shadow-xl">
<form action="{{ route('product-groups.update', $productGroup) }}" method="POST">
@method('PUT')
@csrf
<div class="card-body">
<h2 class="card-title">{{ __('Edit product group') }}</h2>
<x-show-message-bags/>
@include('productGroups.form')
<div class="card-actions justify-end">
<button type="submit" class="btn btn-primary">{{ __('Edit') }}</button>
</div>
</div>
</form>
</div>
</x-app-layout>
15 changes: 15 additions & 0 deletions resources/views/productGroups/form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="grid grid-cols-2 gap-5">
<div class="col-span-2 md:col-span-1">
<label for="code" class="input input-bordered flex items-center gap-2">
{{ __('Account code') }}
<input id="code" name="code" type="text" value="{{ old('code', $productGroup->code ?? '') }}" class="grow" placeholder="کد طرف حساب" />
</label>
</div>

<div class="col-span-2 md:col-span-1">
<label for="name" class="input input-bordered flex items-center gap-2">
{{ __('Name') }}
<input id="name" name="name" type="text" value="{{ old('name', $productGroup->name ?? '') }}" class="grow" placeholder="نام" />
</label>
</div>
</div>
44 changes: 44 additions & 0 deletions resources/views/productGroups/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Products Group') }}
</h2>
</x-slot>
<x-show-message-bags/>
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<div class="card-actions">
<a href="{{ route('product-groups.create') }}" class="btn btn-primary">{{ __("Create product group") }}</a>
</div>

<table class="table w-full mt-4 overflow-auto">
<thead>
<tr>
<th class="px-4 py-2">{{ __('Account code') }}</th>
<th class="px-4 py-2">{{ __('Name') }}</th>
<th class="px-4 py-2">{{ __('Action') }}</th>
</tr>
</thead>
<tbody>

@foreach ($productGroups as $productGroup)
<tr>
<td class="px-4 py-2">{{ $productGroup->code }}</td>
<td class="px-4 py-2">{{ $productGroup->name }}</td>
<td class="px-4 py-2">
<a href="{{ route('product-groups.edit', $productGroup) }}"
class="btn btn-sm btn-info">Edit</a>
<form action="{{ route('product-groups.destroy', $productGroup) }}" method="POST"
class="inline-block">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-error">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</x-app-layout>
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Route::resource('subjects', Controllers\SubjectController::class);
Route::resource('transactions', Controllers\TransactionController::class);
Route::resource('products', Controllers\ProductController::class);
Route::resource('product-groups', Controllers\ProductGroupController::class);
Route::resource('customers', Controllers\CustomerController::class);
Route::resource('customer-groups', Controllers\CustomerGroupController::class);
Route::resource('bank-accounts', Controllers\BankAccountController::class);
Expand Down