- Import products via a CSV
- Authentication for user with reigstration,login and logout
- End users should be able to add products in to cart and they should be able to place an order
https://www.loom.com/share/3bb11fedbe1d46bc8ccf937b4b948f77
Clone the project
git@github.com:nipunTharuksha/ec-threls.git
Go to the project directory
cd ec-threls
Install dependencies
composer install
Create .env and update DB credentials
Initialize the project (Below command will execute all required commands as a sequence)
php artisan project:init
Start the server
php artisan serve
https://documenter.getpostman.com/view/19165023/2s8YzMXQYe#intro
- Laravel-model-states - Used for order states ,payment states .
public static function config():StateConfig {
return parent::config()
->default(PaymentPendingState::class)
->allowTransition(PaymentPendingState::class, PaymentDeclinedState::class)
->allowTransition(PaymentPendingState::class, PaymentAcceptedState::class);
}
- Laravel-query-builder - Used for query filters
/**
* @return DataResourceCollection
*/
public function index(): DataResourceCollection
{
$productsQuery = QueryBuilder::for(Product::with('brand:id,name'))
->select(['id', 'name', 'price', 'brand_id', 'currency', 'created_at'])
->allowedFilters([
AllowedFilter::callback('search', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->where('name', 'like', '%' . $value . '%')
->orWhereHas('brand', function ($query) use ($value) {
$query->where('name', 'like', '%' . $value . '%');
});
});
})
]);
return new DataResourceCollection($this->paginate($productsQuery));
}
- Laravel-permission - Used for user roles
Route::middleware(['auth:api', 'role:user'])
$user = User::create($data);
$user->assignRole('user');
- Laravel-enum - Used for payment types
/**
* @method static static COD()
* @method static static CP()
*/
final class OrderPaymentType extends Enum
{
const COD = 'COD'; // Cash on delivery
const CP = 'CP'; // Card payment
}
- Laravel-API-response-helpers - Used for responses
return $this->respondCreated();
- Laravel-cart-manager - Used for cart related functionalities
/**
* @return DataResource
*/
public function cartData(): DataResource
{
cart()->setUser(auth()->id());
return new DataResource([cart()->totals() + ['items' => cart()->items(true)]]);
}
/**
* @param $cartItemId
* @return JsonResponse
* @throws ValidationException
*/
public function removeFromCart($cartItemId): JsonResponse
{
cart()->setUser(auth()->id());
$this->validateItem($cartItemId);
cart()->removeAt($this->getItemIndex($cartItemId));
return $this->respondNoContent();
}
/**
* @return JsonResponse
*/
public function deleteCart(): JsonResponse
{
cart()->setUser(auth()->id());
cart()->clear();
return $this->respondNoContent();
}