Skip to content

Commit 53a3635

Browse files
committed
Added: Multiple insert data product
1 parent 5455c0f commit 53a3635

File tree

7 files changed

+831
-4
lines changed

7 files changed

+831
-4
lines changed

backend/app/Http/Controllers/ProductController.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function index(Request $request)
2222
$data = Product::where(function($query) use ($search) {
2323
$query->where('name', 'LIKE', "%{$search}%");
2424
$query->orWhere('description', 'LIKE', "%{$search}%");
25+
$query->orWhere('price', 'LIKE', "%{$search}%");
2526
})->latest()->paginate($perPage);
2627

2728
return response()->json([
@@ -70,6 +71,37 @@ public function store(Request $request)
7071
}
7172
}
7273

74+
public function multipleStore(Request $request)
75+
{
76+
$validatedData = $request->validate([
77+
'inputs.*.name' => 'required',
78+
'inputs.*.description' => '',
79+
'inputs.*.price' => 'numeric'
80+
]);
81+
82+
try
83+
{
84+
$createdData = [];
85+
foreach ($validatedData['inputs'] as $input) {
86+
$createdData[] = Product::create($input);
87+
}
88+
89+
return response()->json([
90+
'data' => $createdData,
91+
'success' => true,
92+
'message' => 'Data created successfully'
93+
], JsonResponse::HTTP_CREATED);
94+
}
95+
catch (Exception $e)
96+
{
97+
return response()->json([
98+
'data' => [],
99+
'success' => false,
100+
'message' => $e->getMessage()
101+
], JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
102+
}
103+
}
104+
73105
/**
74106
* Display the specified resource.
75107
*/

backend/routes/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
Route::group(['middleware' => ['auth:api', 'role:admin']], function () {
4141
Route::resource('/products', ProductController::class);
42+
Route::post('/products/multiple-store', [ProductController::class, 'multipleStore']);
4243
Route::resource('/gallery', GalleryController::class);
4344
});
4445

frontend/src/components/Footer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function Footer() {
88
By
99
<a href="https://github.com/fhmiibrhimdev"> Fahmi Ibrahim</a>
1010
</div>
11-
<div className="footer-right">0.1.6</div>
11+
<div className="footer-right">0.1.7</div>
1212
</footer>
1313
);
1414
}

frontend/src/components/Navigation.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export default function Navigation() {
128128
location.pathname === "/general-feature" ||
129129
location.pathname === "/advanced-feature" ||
130130
location.pathname === "/products" ||
131-
location.pathname === "/gallery"
131+
location.pathname === "/gallery" ||
132+
location.pathname === "/multiple-insert"
132133
? "active"
133134
: ""
134135
}`}
@@ -197,6 +198,18 @@ export default function Navigation() {
197198
Gallery
198199
</NavLink>
199200
</li>
201+
<li
202+
className={`nav-item ${
203+
location.pathname ===
204+
"/multiple-insert"
205+
? "active"
206+
: ""
207+
}`}
208+
>
209+
<NavLink href="/multiple-insert">
210+
Multiple Insert
211+
</NavLink>
212+
</li>
200213
</>
201214
)}
202215
</ul>

frontend/src/components/Router.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Error403 from "../pages/Error/403";
1212
import Error404 from "../pages/Error/404";
1313
import Gallery from "../pages/Gallery/Gallery";
1414
import Profile from "../pages/Profile/Profile";
15+
import MultipleInsert from "../pages/MultipleInsert/MultipleInsert";
1516

1617
export default function Router() {
1718
return (
@@ -89,6 +90,15 @@ export default function Router() {
8990
</MainLayout>
9091
}
9192
/>
93+
<Route
94+
exact
95+
path="/multiple-insert"
96+
element={
97+
<MainLayout>
98+
<MultipleInsert />
99+
</MainLayout>
100+
}
101+
/>
92102
<Route path="*" element={<Error404 />} />
93103
</Routes>
94104
);

0 commit comments

Comments
 (0)