This project aims to create a product catalog with the ability to sort and filter by category or price. Each product has a name, description, price, image, and belongs to one or more categories. Categories have a name and can have a parent category. The system allows for product creation via web and command-line interfaces and ensures automated testing for product creation.
Create products via Laravel Artisan CLI. Filter by category and sort by price via view.
- Ability to create a product (from web and cli)
- A listing products with ability to sort by price, or/and filter by a category (from web)
- Git : Git is a free and open source distributed version control system.
- Composer : is a tool for dependency management.
- Node.js : is a cross-platform, open-source server environment.
Note You can check requirements for laravel 10 and its versions using this link.
To install the project, first open to your work directory and use git clone
clone it to your local machine. Then, use composer install
to download the necessary PHP packages and npm install
to download the required JavaScript packages. Once installed, run the npm run build
command to bundle your application's assets, making them ready for production deployment.
Next steps after installing the project, Start Laravel's local development server using the Laravel's Artisan CLI serve command php artisan serve
, Once you have started the Artisan development server, your application will be accessible in your web browser at http://127.0.0.1:8000
.
Ability to create a product using the laravel Artisan CLI:
php artisa product:create [arguments] [options]
php artisan product:create <name> <description> <price> <category_id>
Note In the event that no argument is not included, you will be taken to a asking about it.
With the aim of disrupting ask
option, You must using the next option:
php artisa product:create <name> <description> <price> <category_id> [-a|--ask=false]
In cases you want to interact with the Laravel Artisan CLI product create, use command:
php artisan product:create
Ask | Input |
---|---|
product name | string, min:3, max:55 |
product description | required, string, min:10, max:5000 |
product price | required, numeric, min:1 |
product category_id | required, numeric, id is exists in categories table |
app/
├── Abstracts/
│ ├── AbstractBaseResourceRepository.php
│ ├── AbstractBaseResourceService.php
├── Console/
│ ├── Commands.php
│ │ └── Products
│ │ └──CreateProductCommand.php
├── Http/
│ ├── Controllers/
│ │ ├── Api/
│ │ │ ├── CategoryController.php
│ │ │ └── ProductController.php
│ │ └── ...
│ ├── Requests/
│ │ ├── FilterProductRequest.php
│ │ ├── StoreProductRequest.php
│ │ └── ...
│ └── ...
├── Interfaces/
│ ├── RepositoryInterfaces/
│ │ ├── CategoryRepositoryInterface.php
│ │ └── ProductRepositoryInterface.php
│ ├── ServiceInterfaces/
│ │ ├── CategoryServiceInterface.php
│ │ └── ProductServiceInterface.php
│ ├── ValidationServiceInterface/
│ │ └── ProductValidationServiceInterface.php
│ ├── BaseResourceServiceInterface.php
│ └── BaseResourceRepositoryInterface.php
│ └── BaseValidationServiceInterface.php
├── Models/
│ ├── Category.php
│ ├── Product.php
│ ├── SubCategory.php
│ └── ...
├── Providers/
│ ├── AppServiceProvider.php
│ ├── RepositoryServiceProvider.php
│ └── ...
├── Repositories/
│ ├── CategoryRepository.php
│ └── ProductRepository.php
├── Services/
│ ├── ValidationServices/
│ │ └── ProductValidationService.php
│ ├── CategoryService.php
│ ├── CategoryService.php
│ └── ProductService.php
├── Traits/
│ ├── CliValidator.php
│ └── ImageUploaderTrait.php
└── ...
- RepositoryInterfaces
- ServiceInterfaces
- ValidationServiceInterfaces
- BaseResourceRepositoryInterface
- BaseResourceServiceInterface
- BaseValidationServiceInterface
Keys | User Stories |
---|---|
YC-1 | As a user, I want to create a new product (from web) |
YC-2 | As a user, I want to create a new product (from CLI) |
YC-3 | As a user, I want to list products (from web) |
YC-4 | As a user, I want to sort products (from web) |
YC-5 | As a user, I want to filter products by category (from web) |
Command to run Artisan development server:
php artisan serve
Once you have started the Artisan development server, your application will be accessible in your web browser at http://127.0.0.1:8000
.
After this you can interact with the application.
Command to run Laravel Artisan CLI to create product with arguments:
php artisan product:create <name> <description> <price> <category_id>
php artisan product:create t-shirt "Bold, vibrant and comfortable - make a statement with our unique t-shirt designs" 200 3
Command to run Laravel Artisan CLI to create product with asking method:
php artisan product:create
Product Name?:
> t-shirt
Product Description?:
> Bold, vibrant and comfortable - make a statement with our unique t-shirt designs
Product Price?:
> 200
Show All Categories.
+----+--------------------------+
| id | name |
+----+--------------------------+
| 1 | Brielle Morissette |
| 2 | Trey Nienow |
| 3 | Prof. Clemens Raynor Jr. |
| 4 | Mr. Jordan Halvorson II |
| 5 | Dewitt Shields |
+----+--------------------------+
Choise Product Category With Id?:
> 3
Product Created Successfully.
Exception
The price field must be a number.
at app\Traits\CliValidator.php:23
19▕ $attribute => $validation
20▕ ]);
21▕
➜ 23▕ throw new Exception($validator->errors()->first($attribute));
24▕ }
25▕
26▕ return $value;
27▕ }
// ...