Project Introduction

The E-Commerce Website Project is an innovative initiative aimed at creating a robust online platform for buying and selling products and services. With the rapid growth of online shopping, this project seeks to provide a seamless and user-friendly experience for customers while enabling businesses to reach a wider audience. The e-commerce website will feature a diverse range of products, secure payment options, and efficient order management systems to enhance customer satisfaction and drive sales.

The platform will be designed with a responsive layout, ensuring accessibility across various devices, including desktops, tablets, and smartphones. Key functionalities will include product browsing, advanced search options, user reviews, shopping cart management, and customer support. By integrating modern technologies and best practices, the E-Commerce Website Project aims to create a competitive online marketplace that meets the needs of both consumers and retailers.

Project Objectives

  • To develop a user-friendly interface for easy navigation and product discovery.
  • To implement secure payment gateways for safe and reliable transactions.
  • To provide comprehensive product information, including descriptions, images, and reviews.
  • To enable efficient order processing and inventory management for businesses.
  • To integrate customer support features, such as live chat and FAQs, for enhanced service.
  • To implement user account management for personalized shopping experiences.
  • To ensure mobile responsiveness for optimal viewing on all devices.
  • To utilize analytics tools to track user behavior and improve marketing strategies.

Project Modules

1. User Management Module

  • User Registration/Login: Allow users to create accounts and log in securely.
  • Profile Management: Enable users to manage their profiles, including personal information, addresses, and payment methods.
  • Role Management: Differentiate between user roles (e.g., customer, admin, vendor) with varying permissions.

2. Product Management Module

  • Product Catalog: Display products with images, descriptions, prices, and specifications.
  • Inventory Management: Track stock levels, manage inventory, and set alerts for low stock.
  • Categories and Tags: Organize products into categories and use tags for better searchability.

3. Shopping Cart Module

  • Add to Cart: Allow users to add products to their shopping cart.
  • Cart Management: Enable users to view, update quantities, or remove items from their cart.
  • Save for Later: Provide an option to save items for future purchases.

4. Checkout Module

  • Guest Checkout: Allow users to check out without creating an account.
  • Address Management: Enable users to enter and manage shipping and billing addresses.
  • Payment Gateway Integration: Integrate with payment processors (e.g., PayPal, Stripe) for secure transactions.
  • Order Summary: Provide a summary of the order before finalizing the purchase.

5. Order Management Module

  • Order Tracking: Allow users to track the status of their orders.
  • Order History: Enable users to view their past orders and re-order items.
  • Returns and Refunds: Provide a process for users to initiate returns and refunds.

6. Search and Filtering Module

  • Search Functionality: Implement a search bar to allow users to find products by keywords.
  • Filtering Options: Enable filtering by categories, price range, ratings, and other attributes.

7. Wishlist Module

  • Create Wishlist: Allow users to create and manage wishlists for future purchases.
  • Share Wishlist: Enable users to share their wishlists with friends or family.

8. Promotions and Discounts Module

  • Coupon Management: Allow users to apply discount codes during checkout.
  • Sales and Promotions: Highlight ongoing sales, special offers, and seasonal promotions.

9. Customer Reviews and Ratings Module

  • Product Reviews: Allow customers to leave reviews and ratings for products.
  • Moderation Tools: Provide options for admins to moderate reviews.

10. Admin Dashboard

  • User Management: Admins can manage users, including banning or promoting users.
  • Product Management: Admins can add, edit, or remove products from the catalog.
  • Order Management: Admins can view and manage all orders, including processing and shipping.

11. Analytics and Reporting Module

  • Sales Analytics: Provide insights into sales performance, revenue, and customer behavior.
  • Inventory Reports: Track inventory levels and identify best-selling products.

12. Content Management System (CMS)

  • Blog/Article Management: Allow for the creation of content to engage customers and improve SEO.
  • Static Pages: Manage pages like About Us, Contact Us, and FAQs.

13. Shipping and Delivery Module

  • Shipping Options: Provide various shipping methods and rates.
  • Address Validation: Validate shipping addresses to reduce errors.

Project Tables Queries


-- Create Users Table
CREATE TABLE Users (
UserId INT PRIMARY KEY IDENTITY(1,1),
Username NVARCHAR(50) NOT NULL UNIQUE,
PasswordHash NVARCHAR(256) NOT NULL,
Email NVARCHAR(100) NOT NULL UNIQUE,
RoleId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (RoleId) REFERENCES Roles(RoleId)
);
-- Create Roles Table
CREATE TABLE Roles (
RoleId INT PRIMARY KEY IDENTITY(1,1),
RoleName NVARCHAR(50) NOT NULL UNIQUE
);
-- Create Products Table
CREATE TABLE Products (
ProductId INT PRIMARY KEY IDENTITY(1,1),
Name NVARCHAR(100) NOT NULL,
Description NVARCHAR(MAX) NOT NULL,
Price DECIMAL(18, 2) NOT NULL,
Stock INT NOT NULL,
CategoryId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId)
);
-- Create Categories Table
CREATE TABLE Categories (
CategoryId INT PRIMARY KEY IDENTITY(1,1),
Name NVARCHAR(100) NOT NULL UNIQUE
);
-- Create CartItems Table
CREATE TABLE CartItems (
CartItemId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
ProductId INT,
Quantity INT NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId),
FOREIGN KEY (ProductId) REFERENCES Products(ProductId)
);
-- Create Orders Table
CREATE TABLE Orders (
OrderId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
OrderDate DATETIME DEFAULT GETDATE(),
TotalAmount DECIMAL(18, 2) NOT NULL,
ShippingAddressId INT,
Status NVARCHAR(50) NOT NULL,
FOREIGN KEY (User Id) REFERENCES Users(UserId),
FOREIGN KEY (ShippingAddressId) REFERENCES ShippingAddresses(ShippingAddressId)
);
-- Create OrderItems Table
CREATE TABLE OrderItems (
OrderItemId INT PRIMARY KEY IDENTITY(1,1),
OrderId INT,
ProductId INT,
Quantity INT NOT NULL,
Price DECIMAL(18, 2) NOT NULL,
FOREIGN KEY (OrderId) REFERENCES Orders(OrderId),
FOREIGN KEY (ProductId) REFERENCES Products(ProductId)
);
-- Create Reviews Table
CREATE TABLE Reviews (
ReviewId INT PRIMARY KEY IDENTITY(1,1),
ProductId INT,
UserId INT,
Rating INT CHECK (Rating >= 1 AND Rating <= 5),
Comment NVARCHAR(MAX),
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (ProductId) REFERENCES Products(ProductId),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create Wishlists Table
CREATE TABLE Wishlists (
WishlistId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create WishlistItems Table
CREATE TABLE WishlistItems (
WishlistItemId INT PRIMARY KEY IDENTITY(1,1),
WishlistId INT,
ProductId INT,
FOREIGN KEY (WishlistId) REFERENCES Wishlists(WishlistId),
FOREIGN KEY (ProductId) REFERENCES Products(ProductId)
);
-- Create Coupons Table
CREATE TABLE Coupons (
CouponId INT PRIMARY KEY IDENTITY(1,1),
Code NVARCHAR(50) NOT NULL UNIQUE,
DiscountAmount DECIMAL(18, 2) NOT NULL,
ExpirationDate DATETIME NOT NULL,
IsActive BIT DEFAULT 1
);
-- Create ShippingAddresses Table
CREATE TABLE ShippingAddresses (
ShippingAddressId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
AddressLine1 NVARCHAR(256) NOT NULL,
AddressLine2 NVARCHAR(256),
City NVARCHAR(100) NOT NULL,
State NVARCHAR(100) NOT NULL,
ZipCode NVARCHAR(20) NOT NULL,
Country NVARCHAR(100) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);

Explanation of the Tables

Users: Stores user information, including username, password hash, email, and role.

Roles: Defines user roles (e.g., Admin, Customer).

Products: Contains product details, including name, description, price, stock, and category.

Categories: Organizes products into categories.

CartItems: Represents items in a user's shopping cart.

Creating Models and Migrations

To create the models and migrations for the provided MySQL schema in Laravel 11, you can follow these steps. Below, I will provide the migration files and the corresponding Eloquent models for each table.

Step 1: Create Migrations

You can create migrations using the Artisan command. For example, to create a migration for the Users table, you would run:


php artisan make:migration create_users_table

Repeat this for each table. Below are the migration files for each table based on your SQL schema.

Migration for Users Table


// database/migrations/2025_02_01_000001_create_users_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id('User Id');
$table->string('Username', 50)->unique();
$table->string('PasswordHash', 256);
$table->string('Email', 100)->unique();
$table->foreignId('RoleId')->nullable()->constrained('roles', 'RoleId');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('users');
}
}

Migration for Roles Table


// database/migrations/2025_02_01_000002_create_roles_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id('RoleId');
$table->string('RoleName', 50)->unique();
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}

Migration for Products Table


// database/migrations/2025_02_01_000003_create_products_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductsTable extends Migration
{
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id('ProductId');
$table->string('Name', 100);
$table->text('Description');
$table->decimal('Price', 18, 2);
$table->integer('Stock');
$table->foreignId('CategoryId')->nullable()->constrained('categories', 'CategoryId');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('products');
}
}

Migration for Categories Table


// database/migrations/2025_02_01_000003_create_categories_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCategoriesTable extends Migration
{
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id('CategoryId');
$table->string('Name', 100)->unique();
});
}
public function down()
{
Schema::dropIfExists('categories');
}
}

Migration for CartItems Table


// database/migrations/2025_02_01_000004_create_cart_items_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCartItemsTable extends Migration
{
public function up()
{
Schema::create('cart_items', function (Blueprint $table) {
$table->id('CartItemId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->foreignId('ProductId')->constrained('products', 'ProductId');
$table->integer('Quantity');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('cart_items');
}
}

Migration for Orders Table


// database/migrations/2025_02_01_000005_create_orders_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOrdersTable extends Migration
{
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->id('OrderId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->dateTime('OrderDate')->default(now());
$table->decimal('TotalAmount', 18, 2);
$table->foreignId('ShippingAddressId')->nullable()->constrained('shipping_addresses', 'ShippingAddressId');
$table->string('Status', 50);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('orders');
}
}

Migration for OrderItems Table


// database/migrations/2025_02_01_000006_create_order_items_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOrderItemsTable extends Migration
{
public function up()
{
Schema::create('order_items', function (Blueprint $table) {
$table->id('OrderItemId');
$table->foreignId('OrderId')->constrained('orders', 'OrderId');
$table->foreignId('ProductId')->constrained('products', 'ProductId');
$table->integer('Quantity');
$table->decimal ('Price', 18, 2);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('order_items');
}
}

Migration for Reviews Table


// database/migrations/2025_02_01_000007_create_reviews_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateReviewsTable extends Migration
{
public function up()
{
Schema::create('reviews', function (Blueprint $table) {
$table->id('ReviewId');
$table->foreignId('ProductId')->constrained('products', 'ProductId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->integer('Rating')->check('Rating >= 1 AND Rating <= 5');
$table->text('Comment')->nullable();
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('reviews');
}
}

Migration for Wishlists Table


// database/migrations/2025_02_01_000008_create_wishlists_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWishlistsTable extends Migration
{
public function up()
{
Schema::create('wishlists', function (Blueprint $table) {
$table->id('WishlistId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('wishlists');
}
}

Migration for WishlistItems Table


// database/migrations/2025_02_01_000009_create_wishlist_items_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWishlistItemsTable extends Migration
{
public function up()
{
Schema::create('wishlist_items', function (Blueprint $table) {
$table->id('WishlistItemId');
$table->foreignId('WishlistId')->constrained('wishlists', 'WishlistId');
$table->foreignId('ProductId')->constrained('products', 'ProductId');
});
}
public function down()
{
Schema::dropIfExists('wishlist_items');
}
}

Migration for Coupons Table


// database/migrations/2025_02_01_000010_create_coupons_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCouponsTable extends Migration
{
public function up()
{
Schema::create('coupons', function (Blueprint $table) {
$table->id('CouponId');
$table->string('Code', 50)->unique();
$table->decimal('DiscountAmount', 18, 2);
$table->dateTime('ExpirationDate');
$table->boolean('IsActive')->default(true);
});
}
public function down()
{
Schema::dropIfExists('coupons');
}
}

Migration for ShippingAddresses Table


// database/migrations/2025_02_01_000011_create_shipping_addresses_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateShippingAddressesTable extends Migration
{
public function up()
{
Schema::create('shipping_addresses', function (Blueprint $table) {
$table->id('ShippingAddressId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->string('AddressLine1', 256);
$table->string('AddressLine2', 256)->nullable();
$table->string('City', 100);
$table->string('State', 100);
$table->string('ZipCode', 20);
$table->string('Country', 100);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('shipping_addresses');
}
}

Step 2: Create Eloquent Models

You can create models using the Artisan command. For example, to create a model for the User table, you would run:


php artisan make:model User

User Model


// app/Models/User.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasFactory;
protected $table = 'users';
protected $fillable = [
'Username',
'PasswordHash',
'Email',
'RoleId',
];
public function role()
{
return $this->belongsTo(Role::class, 'RoleId');
}
public function cartItems()
{
return $this->hasMany(CartItem::class, 'User Id');
}
public function orders()
{
return $this->hasMany(Order::class, 'User Id');
}
public function reviews()
{
return $this->hasMany(Review::class, 'User Id');
}
public function wishlists()
{
return $this->hasMany(Wishlist::class, 'User Id');
}
public function shippingAddresses()
{
return $this->hasMany(ShippingAddress::class, 'User Id');
}
}

Role Model


// app/Models/Role.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
use HasFactory;
protected $table = 'roles';
protected $fillable = [
'RoleName',
];
public function users()
{
return $this->hasMany(User::class, 'RoleId');
}
}

Product Model


// app/Models/Product.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
use HasFactory;
protected $table = 'products';
protected $fillable = [
'Name',
'Description',
'Price',
'Stock',
'CategoryId',
];
public function category()
{
return $this->belongsTo(Category::class, 'CategoryId');
}
public function cartItems()
{
return $this->hasMany(CartItem::class, 'ProductId');
}
public function orderItems()
{
return $this->hasMany(OrderItem::class, 'ProductId');
}
public function reviews()
{
return $this->hasMany(Review::class, 'ProductId');
}
public function wishlistItems()
{
return $this->hasMany(WishlistItem::class, 'ProductId');
}
}

Category Model


// app/Models/Category.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use HasFactory;
protected $table = 'categories';
protected $fillable = [
'Name',
];
public function products()
{
return $this->hasMany(Product::class, 'CategoryId');
}
}

CartItem Model


// app/Models/CartItem.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CartItem extends Model
{
use HasFactory;
protected $table = 'cart_items';
protected $fillable = [
'User Id',
'ProductId',
'Quantity',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
public function product()
{
return $this->belongsTo(Product::class, 'ProductId');
}
}

Order Model


// app/Models/Order.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
use HasFactory;
protected $table = 'orders';
protected $fillable = [
'User Id',
'OrderDate',
'TotalAmount',
'ShippingAddressId',
'Status',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
public function orderItems()
{
return $this->hasMany(OrderItem::class, 'OrderId');
}
public function shippingAddress()
{
return $this->belongsTo(ShippingAddress::class, 'ShippingAddressId');
}
}

OrderItem Model


// app/Models/OrderItem.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class OrderItem extends Model
{
use HasFactory;
protected $table = 'order_items';
protected $fillable = [
'OrderId',
'ProductId',
'Quantity',
'Price',
];
public function order()
{
return $this->belongsTo(Order::class, 'OrderId');
}
public function product()
{
return $this->belongsTo(Product::class, 'ProductId');
}
}

Review Model


// app/Models/Review.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Review extends Model
{
use HasFactory;
protected $table = 'reviews';
protected $fillable = [
'ProductId',
'User Id',
'Rating',
'Comment',
];
public function product()
{
return $this->belongsTo(Product::class, 'ProductId');
}
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
}

Wishlist Model


// app/Models/Wishlist.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Wishlist extends Model
{
use HasFactory;
protected $table = 'wishlists';
protected $fillable = [
'User Id',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
public function wishlistItems()
{
return $this->hasMany(WishlistItem::class, 'WishlistId');
}
}

WishlistItem Model


// app/Models/WishlistItem.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class WishlistItem extends Model
{
use HasFactory;
protected $table = 'wishlist_items';
protected $fillable = [
'WishlistId',
'ProductId',
];
public function wishlist()
{
return $this->belongsTo(Wishlist::class, 'WishlistId');
}
public function product()
{
return $this->belongsTo(Product::class, 'ProductId');
}
}

Coupon Model


// app/Models/Coupon.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Coupon extends Model
{
use HasFactory;
protected $table = 'coupons';
protected $fillable = [
'Code',
'DiscountAmount',
'ExpirationDate',
'IsActive',
];
}

ShippingAddress Model


// app/Models/ShippingAddress.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ShippingAddress extends Model
{
use HasFactory;
protected $table = 'shipping_addresses';
protected $fillable = [
'User Id',
'AddressLine1',
'AddressLine2',
'City',
'State',
'ZipCode',
'Country',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
}

Step 3: Run Migrations

After creating the migration files and models, you can run the migrations using the following command:


php artisan migrate

This will create the tables in your database according to the defined schema.

Creating Controllers for Each Model

To create controllers for each model with complete CRUD operations in Laravel, you can use the Artisan command to generate resource controllers. Below, I will provide the commands to create the controllers and the basic structure for each controller, including the CRUD operations.

Step 1: Create Resource Controllers

You can create a resource controller for each model using the following command:


php artisan make:controller UserController --resource
php artisan make:controller RoleController --resource
php artisan make:controller ProductController --resource
php artisan make:controller CategoryController --resource
php artisan make:controller CartItemController --resource
php artisan make:controller OrderController --resource
php artisan make:controller OrderItemController --resource
php artisan make:controller ReviewController --resource
php artisan make:controller WishlistController --resource
php artisan make:controller WishlistItemController --resource
php artisan make:controller CouponController --resource
php artisan make:controller ShippingAddressController --resource

Step 2: Implement CRUD Operations

Below are the basic implementations for each controller. You can expand these methods as needed.

UserController


// app/Http/Controllers/UserController.php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index()
{
$users = User::all();
return view('users.index', compact('users'));
}
public function create()
{
return view('users.create');
}
public function store(Request $request)
{
$request->validate([
'Username' => 'required|unique:users|max:50',
'PasswordHash' => 'required',
'Email' => 'required|email|unique:users|max:100',
'RoleId' => 'nullable|exists:roles,RoleId',
]);
User::create($request->all());
return redirect()->route('users.index')->with('success', 'User created successfully.');
}
public function show(User $user)
{
return view('users.show', compact('user'));
}
public function edit(User $user)
{
return view('users.edit', compact('user'));
}
public function update(Request $request, User $user)
{
$request->validate([
'Username' => 'required|max:50|unique:users,Username,' . $user->id,
'PasswordHash' => 'required',
'Email' => 'required|email|max:100|unique:users,Email,' . $user->id,
'RoleId' => 'nullable|exists:roles,RoleId',
]);
$user->update($request->all());
return redirect()->route('users.index')->with('success', 'User updated successfully.');
}
public function destroy(User $user)
{
$user->delete();
return redirect()->route('users.index')->with('success', 'User deleted successfully.');
}
}

RoleController


// app/Http/Controllers/RoleController.php
namespace App\Http\Controllers;
use App\Models\Role;
use Illuminate\Http\Request;
class RoleController extends Controller
{
public function index()
{
$roles = Role::all();
return view('roles.index', compact('roles'));
}
public function create()
{
return view('roles.create');
}
public function store(Request $request)
{
$request->validate([
'RoleName' => 'required|unique:roles|max:50',
]);
Role::create($request->all());
return redirect()->route('roles.index')->with('success', 'Role created successfully.');
}
public function show(Role $role)
{
return view('roles.show', compact('role'));
}
public function edit(Role $role)
{
return view('roles.edit', compact('role'));
}
public function update(Request $request, Role $role)
{
$request->validate([
'RoleName' => 'required|max:50|unique:roles,RoleName,' . $role->id,
]);
$role->update($request->all());
return redirect()->route('roles.index')->with('success', 'Role updated successfully.');
}
public function destroy(Role $role)
{
$role->delete();
return redirect()->route('roles.index')->with('success', 'Role deleted successfully.');
}
}

ProductController


// app/Http/Controllers/ProductController.php
namespace App\Http\Controllers;
use App\Models\Product;
use App\Models\Category;
use Illuminate\Http\Request;
class ProductController extends Controller
{
public function index()
{
$products = Product::all();
return view('products.index', compact('products'));
}
public function create()
{
$categories = Category::all();
return view('products.create', compact('categories'));
}
public function store(Request $request)
{
$request->validate([
'Name' => 'required|max:100',
'Description' => 'required',
'Price' => 'required|numeric',
'Stock' => 'required|integer',
'CategoryId' => 'nullable|exists:categories,CategoryId',
]);
Product::create($request->all());
return redirect()->route('products.index')->with('success', 'Product created successfully.');
}
public function show(Product $product)
{
return view('products.show', compact('product'));
}
public function edit(Product $product)
{
$categories = Category::all();
return view('products.edit', compact('product', 'categories'));
}
public function update(Request $request, Product $product)
{
$request->validate([
'Name' => 'required|max:100',
'Description' => 'required',
'Price' => 'required|numeric',
'Stock' => 'required|integer',
'CategoryId' => 'nullable|exists:categories,CategoryId',
]);
$product->update($request->all());
return redirect()->route('products.index')->with('success', 'Product updated successfully.');
}
public function destroy(Product $product)
{
$product->delete();
return redirect()->route('products.index')->with('success', 'Product deleted successfully.');
}
}

CategoryController


// app/Http/Controllers/CategoryController.php
namespace App\Http\Controllers;
use App\Models\Category;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
public function index()
{
$categories = Category::all();
return view('categories.index', compact('categories'));
}
public function create()
{
return view('categories.create');
}
public function store(Request $request)
{
$request->validate([
'Name' => 'required|unique:categories|max:100',
]);
Category::create($request->all());
return redirect()->route('categories.index')->with('success', 'Category created successfully.');
}
public function show(Category $category)
{
return view('categories.show', compact('category'));
}
public function edit(Category $category)
{
return view('categories.edit', compact('category'));
}
public function update(Request $request, Category $category)
{
$request->validate([
'Name' => 'required|max:100|unique:categories,Name,' . $category->id,
]);
$category->update($request->all());
return redirect()->route('categories.index')->with('success', 'Category updated successfully.');
}
public function destroy(Category $category)
{
$category->delete();
return redirect()->route('categories.index')->with('success', 'Category deleted successfully.');
}
}

CartItemController


// app/Http/Controllers/CartItemController.php
namespace App\Http\Controllers;
use App\Models\CartItem;
use Illuminate\Http\Request;
class CartItemController extends Controller
{
public function index()
{
$cartItems = CartItem::all();
return view('cart_items.index', compact('cartItems'));
}
public function create()
{
return view('cart_items.create');
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'ProductId' => 'required|exists:products,ProductId',
'Quantity' => 'required|integer',
]);
CartItem::create($request->all());
return redirect()->route('cart_items.index')->with('success', 'Cart item created successfully.');
}
public function show(CartItem $cartItem)
{
return view('cart_items.show', compact('cartItem'));
}
public function edit(CartItem $cartItem)
{
return view('cart_items.edit', compact('cartItem'));
}
public function update(Request $request, CartItem $cartItem)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'ProductId' => 'required|exists:products,ProductId',
'Quantity' => 'required|integer',
]);
$cartItem->update($request->all());
return redirect()->route('cart_items.index')->with('success', 'Cart item updated successfully.');
}
public function destroy(CartItem $cartItem)
{
$cartItem->delete();
return redirect()->route('cart_items.index')->with('success', 'Cart item deleted successfully.');
}
}

OrderController


// app/Http/Controllers/OrderController.php
namespace App\Http\Controllers;
use App\Models\Order;
use Illuminate\Http\Request;
class OrderController extends Controller
{
public function index()
{
$orders = Order::all();
return view('orders.index', compact('orders'));
}
public function create()
{
return view('orders.create');
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'TotalAmount' => 'required|numeric',
'ShippingAddressId' => 'nullable|exists:shipping_addresses,ShippingAddressId',
'Status' => 'required|max:50',
]);
Order::create($request->all());
return redirect()->route('orders.index')->with('success', 'Order created successfully.');
}

public function show(Order $order)
{
return view('orders.show', compact('order'));
}
public function edit(Order $order)
{
return view('orders.edit', compact('order'));
}
public function update(Request $request, Order $order)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'TotalAmount' => 'required|numeric',
'ShippingAddressId' => 'nullable|exists:shipping_addresses,ShippingAddressId',
'Status' => 'required|max:50',
]);
$order->update($request->all());
return redirect()->route('orders.index')->with('success', 'Order updated successfully.');
}
public function destroy(Order $order)
{
$order->delete();
return redirect()->route('orders.index')->with('success', 'Order deleted successfully.');
}
}

OrderItemController


// app/Http/Controllers/OrderItemController.php
namespace App\Http\Controllers;
use App\Models\OrderItem;
use Illuminate\Http\Request;
class OrderItemController extends Controller
{
public function index()
{
$orderItems = OrderItem::all();
return view('order_items.index', compact('orderItems'));
}
public function create()
{
return view('order_items.create');
}
public function store(Request $request)
{
$request->validate([
'OrderId' => 'required|exists:orders,OrderId',
'ProductId' => 'required|exists:products,ProductId',
'Quantity' => 'required|integer',
'Price' => 'required|numeric',
]);
OrderItem::create($request->all());
return redirect()->route('order_items.index')->with('success', 'Order item created successfully.');
}
public function show(OrderItem $orderItem)
{
return view('order_items.show', compact('orderItem'));
}
public function edit(OrderItem $orderItem)
{
return view('order_items.edit', compact('orderItem'));
}
public function update(Request $request, OrderItem $orderItem)
{
$request->validate([
'OrderId' => 'required|exists:orders,OrderId',
'ProductId' => 'required|exists:products,ProductId',
'Quantity' => 'required|integer',
'Price' => 'required|numeric',
]);
$orderItem->update($request->all());
return redirect()->route('order_items.index')->with('success', 'Order item updated successfully.');
}
public function destroy(OrderItem $orderItem)
{
$orderItem->delete();
return redirect()->route('order_items.index')->with('success', 'Order item deleted successfully.');
}
}

ReviewController


// app/Http/Controllers/ReviewController.php
namespace App\Http\Controllers;
use App\Models\Review;
use Illuminate\Http\Request;
class ReviewController extends Controller
{
public function index()
{
$reviews = Review::all();
return view('reviews.index', compact('reviews'));
}
public function create()
{
return view('reviews.create');
}
public function store(Request $request)
{
$request->validate([
'ProductId' => 'required|exists:products,ProductId',
'User Id' => 'required|exists:users,User Id',
'Rating' => 'required|integer|between:1,5',
'Comment' => 'nullable|string',
]);
Review::create($request->all());
return redirect()->route('reviews.index')->with('success', 'Review created successfully.');
}
public function show(Review $review)
{
return view('reviews.show', compact('review'));
}
public function edit(Review $review)
{
return view('reviews.edit', compact('review'));
}
public function update(Request $request, Review $review)
{
$request->validate([
'ProductId' => 'required|exists:products,ProductId',
'User Id' => 'required|exists:users,User Id',
'Rating' => 'required|integer|between:1,5',
'Comment' => 'nullable|string',
]);
$review->update($request->all());
return redirect()->route('reviews.index')->with('success', 'Review updated successfully.');
}
public function destroy(Review $review)
{
$review->delete();
return redirect()->route('reviews.index')->with('success', 'Review deleted successfully.');
}
}

WishlistController


// app/Http/Controllers/WishlistController.php
namespace App\Http\Controllers;
use App\Models\Wishlist;
use Illuminate\Http\Request;
class WishlistController extends Controller
{
public function index()
{
$wishlists = Wishlist::all();
return view('wishlists.index', compact('wishlists'));
}
public function create()
{
return view('wishlists.create');
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
]);
Wishlist::create($request->all());
return redirect()->route('wishlists.index')->with('success', 'Wishlist created successfully.');
}
public function show(Wishlist $wishlist)
{
return view('wishlists.show', compact('wishlist'));
}
public function edit(Wishlist $wishlist)
{
return view('wishlists.edit', compact('wishlist'));
}
public function update(Request $request, Wishlist $wishlist)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
]);
$wishlist->update($request->all());
return redirect()->route('wishlists.index')->with('success', 'Wishlist updated successfully.');
}
public function destroy(Wishlist $wishlist)
{
$wishlist->delete();
return redirect()->route('wishlists.index')->with('success', 'Wishlist deleted successfully.');
}
}

WishlistItemController


// app/Http/Controllers/WishlistItemController.php
namespace App\Http\Controllers;
use App\Models\WishlistItem;
use Illuminate\Http\Request;
class WishlistItemController extends Controller
{
public function index()
{
$wishlistItems = WishlistItem::all();
return view('wishlist_items.index', compact('wishlistItems'));
}
public function create()
{
return view('wishlist_items.create');
}
public function store(Request $request)
{
$request->validate([
'WishlistId' => 'required|exists:wishlists,WishlistId',
'ProductId' => 'required|exists:products,ProductId',
]);
WishlistItem::create($request->all());
return redirect()->route('wishlist_items.index')->with('success', 'Wishlist item created successfully.');
}
public function show(WishlistItem $wishlistItem)
{
return view('wishlist_items.show', compact('wishlistItem'));
}
public function edit(WishlistItem $wishlistItem)
{
return view('wishlist_items.edit', compact('wishlistItem'));
}
public function update(Request $request, WishlistItem $wishlistItem)
{
$request->validate([
'WishlistId' => 'required|exists:wishlists,WishlistId',
'ProductId' => 'required|exists:products,ProductId',
]);
$wishlistItem->update($request->all());
return redirect()->route('wishlist_items.index')->with('success', 'Wishlist item updated successfully.');
}
public function destroy(WishlistItem $wishlistItem)
{
$wishlistItem->delete();
return redirect()->route('wishlist_items.index')->with('success', 'Wishlist item deleted successfully.');
}
}

CouponController


// app/Http/Controllers/CouponController.php
namespace App\Http\Controllers;
use App\Models\Coupon;
use Illuminate\Http\Request;
class CouponController extends Controller
{
public function index()
{
$coupons = Coupon::all();
return view('coupons.index', compact('coupons'));
}
public function create()
{
return view('coupons.create');
}
public function store(Request $request)
{
$request->validate([
'Code' => 'required|unique:coupons|max:50',
'DiscountAmount' => 'required|numeric',
'ExpirationDate' => 'required|date',
'IsActive' => 'nullable|boolean',
]);
Coupon::create($request->all());
return redirect()->route('coupons.index')->with('success', 'Coupon created successfully.');
}
public function show(Coupon $coupon)
{
return view('coupons.show', compact('coupon'));
}
public function edit(Coupon $coupon)
{
return view('coupons.edit', compact('coupon'));
}
public function update(Request $request, Coupon $coupon)
{
$request->validate([
'Code' => 'required|max:50|unique:coupons,Code,' . $coupon->id,
'DiscountAmount' => 'required|numeric',
'ExpirationDate' => 'required|date',
'IsActive' => 'nullable|boolean',
]);
$coupon->update($request->all());
return redirect()->route('coupons.index')->with('success', 'Coupon updated successfully.');
}
public function destroy(Coupon $coupon)
{
$coupon->delete();
return redirect()->route('cou pons.index')->with('success', 'Coupon deleted successfully.');
}
}

ShippingAddressController


// app/Http/Controllers/ShippingAddressController.php
namespace App\Http\Controllers;
use App\Models\ShippingAddress;
use Illuminate\Http\Request;
class ShippingAddressController extends Controller
{
public function index()
{
$shippingAddresses = ShippingAddress::all();
return view('shipping_addresses.index', compact('shippingAddresses'));
}
public function create()
{
return view('shipping_addresses.create');
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'AddressLine1' => 'required|max:256',
'AddressLine2' => 'nullable|max:256',
'City' => 'required|max:100',
'State' => 'required|max:100',
'ZipCode' => 'required|max:20',
'Country' => 'required|max:100',
]);
ShippingAddress::create($request->all());
return redirect()->route('shipping_addresses.index')->with('success', 'Shipping address created successfully.');
}
public function show(ShippingAddress $shippingAddress)
{
return view('shipping_addresses.show', compact('shippingAddress'));
}
public function edit(ShippingAddress $shippingAddress)
{
return view('shipping_addresses.edit', compact('shippingAddress'));
}
public function update(Request $request, ShippingAddress $shippingAddress)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'AddressLine1' => 'required|max:256',
'AddressLine2' => 'nullable|max:256',
'City' => 'required|max:100',
'State' => 'required|max:100',
'ZipCode' => 'required|max:20',
'Country' => 'required|max:100',
]);
$shippingAddress->update($request->all());
return redirect()->route('shipping_addresses.index')->with('success', 'Shipping address updated successfully.');
}
public function destroy(ShippingAddress $shippingAddress)
{
$shippingAddress->delete();
return redirect()->route('shipping_addresses.index')->with('success', 'Shipping address deleted successfully.');
}
}

Step 3: Define Routes

You will need to define routes for these controllers in your routes/web.php file. Here's an example of how to set up resource routes for all controllers:


use App\Http\Controllers\UserController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\CartItemController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\OrderItemController;
use App\Http\Controllers\ReviewController;
use App\Http\Controllers\WishlistController;
use App\Http\Controllers\WishlistItemController;
use App\Http\Controllers\CouponController;
use App\Http\Controllers\ShippingAddressController;
Route::resource('users', UserController::class);
Route::resource('roles', RoleController::class);
Route::resource('products', ProductController::class);
Route::resource('categories', CategoryController::class);
Route::resource('cart_items', CartItemController::class);
Route::resource('orders', OrderController::class);
Route::resource('order_items', OrderItemController::class);
Route::resource('reviews', ReviewController::class);
Route::resource('wishlists', WishlistController::class);
Route::resource('wishlist_items', WishlistItemController::class);
Route::resource('coupons', CouponController::class);
Route::resource('shipping_addresses', ShippingAddressController::class);

Step 4: Create Views

You will also need to create views for each of the CRUD operations. The views should be placed in the resources/views directory, organized by model (e.g., users/index.blade.php, products/create.blade.php, etc.).

This setup will provide a complete CRUD interface for each model in your Laravel application. You can customize the views and add additional features as needed.

Creating View Files for Each Controller Using Bootstrap 5

Creating view files for each controller using Bootstrap 5 involves creating a set of Blade templates that will allow you to perform CRUD operations. Below, I will provide a basic structure for each view file, including the necessary Bootstrap 5 components.

Directory Structure

First, create a directory structure for your views. You can organize them like this:


resources/
└── views/
├── users/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── roles/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── products/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── categories/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── cart_items/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── orders/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── order_items/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── reviews/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── wishlists/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── wishlist_items/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── coupons/
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
└── shipping_addresses/
├── index.blade.php
├── create.blade.php
├── edit.blade.php
└── show.blade.php

Base Layout

You can create a base layout file to include Bootstrap 5 and other common elements. Create a file named app.blade.php in resources/views/layouts/.


<!-- resources/views/layouts/app.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<title>@yield('title')</title>
</head>
<body>
<div class="container mt-4">
@yield('content')
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View Files

Users

Index View

<!-- resources/views/users/index.blade.php -->
@extends('layouts.app')
@section('title', 'Users')
@section('content')
<h1>Users</h1>
<a href="{{ route('users.create') }}" class="btn btn-primary mb-3">Create User</a>
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td>{{ $user->Username }}</td>
<td>{{ $user->Email }}</td>
<td>{{ $user->role->RoleName ?? 'N/A' }}</td>
<td>
<a href="{{ route('users.edit', $user) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('users.destroy', $user) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/users/create.blade.php -->
@extends('layouts.app')
@section(' title', 'Create User')
@section('content')
<h1>Create User</h1>
<form action="{{ route('users.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Username" class="form-label">Username</label>
<input type="text" class="form-control" id="Username" name="Username" required>
</div>
<div class="mb-3">
<label for="PasswordHash" class="form-label">Password</label>
<input type="password" class="form-control" id="PasswordHash" name="PasswordHash" required>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type="email" class="form-control" id="Email" name="Email" required>
</div>
<div class="mb-3">
<label for="RoleId" class="form-label">Role</label>
<select class="form-select" id="RoleId" name="RoleId">
<option value="">Select Role</option>
@foreach ($roles as $role)
<option value="{{ $role->RoleId }}">{{ $role->RoleName }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create User</button>
<a href="{{ route('users.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Edit View

<!-- resources/views/users/edit.blade.php -->
@extends('layouts.app')
@section('title', 'Edit User')
@section('content')
<h1>Edit User</h1>
<form action="{{ route('users.update', $user) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Username" class="form-label">Username</label>
<input type="text" class="form-control" id="Username" name="Username" value="{{ $user->Username }}" required>
</div>
<div class="mb-3">
<label for="PasswordHash" class="form-label">Password</label>
<input type="password" class="form-control" id="PasswordHash" name="PasswordHash" required>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type="email" class="form-control" id="Email" name="Email" value="{{ $user->Email }}" required>
</div>
<div class="mb-3">
<label for="RoleId" class="form-label">Role</label>
<select class="form-select" id="RoleId" name="RoleId">
<option value="">Select Role</option>
@foreach ($roles as $role)
<option value="{{ $role->RoleId }}" {{ $user->RoleId == $role->RoleId ? 'selected' : '' }}>{{ $role->RoleName }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Update User</button>
<a href="{{ route('users.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/users/show.blade.php -->
@extends('layouts.app')
@section('title', 'User Details')
@section('content')
<h1>User Details</h1>
<p><strong>Username:</strong> {{ $user->Username }}</p>
<p><strong>Email:</strong> {{ $user->Email }}</p>
<p><strong>Role:</strong> {{ $user->role->RoleName ?? 'N/A' }}</p>
<a href="{{ route('users.edit', $user) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('users.index') }}" class="btn btn-secondary">Back</a>
@endsection

Index View: List all items with options to create, edit, and delete.

Create View: Form to create a new item.

Edit View: Form to edit an existing item.

Show View: Display details of a single item.

Example for Roles

Index View for Roles

<!-- resources/views/roles/index.blade.php -->
@extends('layouts.app')
@section('title', 'Roles')
@section('content')
<h1>Roles</h1>
<a href="{{ route('roles.create') }}" class="btn btn-primary mb-3">Create Role</a>
<table class="table">
<thead>
<tr>
<th>Role Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($roles as $role)
<tr>
<td>{{ $role->RoleName }}</td>
<td>
<a href="{{ route('roles.edit', $role) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('roles.destroy', $role) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View for Roles

<!-- resources/views/roles/create.blade.php -->
@extends('layouts.app')
@section('title', 'Create Role')
@section('content')
<h1>Create Role</h1>
<form action="{{ route('roles.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="RoleName" class="form-label">Role Name</label>
<input type="text" class="form-control" id="RoleName" name="RoleName" required>
</div>
<button type="submit" class="btn btn-primary">Create Role</button>
<a href="{{ route('roles.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Edit View for Roles

<!-- resources/views/roles/edit.blade.php -->
@extends('layouts.app')
@section('title', 'Edit Role')
@section('content')
<h1>Edit Role</h1>
<form action="{{ route('roles.update', $role) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="RoleName" class="form-label">Role Name</label>
<input type="text" class="form-control" id="RoleName" name="RoleName" value="{{ $role->RoleName }}" required>
</div>
<button type="submit" class="btn btn-primary">Update Role</button>
<a href="{{ route('roles.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View for Roles

<!-- resources/views/roles/show.blade.php -->
@extends('layouts.app')
@section('title', 'Role Details')
@section('content')
<h1>Role Details</h1>
<p><strong>Role Name:</strong> {{ $role->RoleName }}</p>
<a href="{{ route('roles.edit', $role) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('roles.index') }}" class="btn btn-secondary">Back</a>
@endsection

Products

Index View

<!-- resources/views/products/index.blade.php -->
@extends('layouts.app')
@section('title', 'Products')
@section('content')
<h1>Products</h1>
<a href="{{ route('products.create') }}" class="btn btn-primary mb-3">Create Product</a>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Stock</th>
<th>Category</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($products as $product)
<tr>
<td>{{ $product->Name }}</td>
<td>{{ $product->Description }}</td>
<td>${{ number_format($product->Price, 2) }}</td>
<td>{{ $product->Stock }}</td>
<td>{{ $product->category->Name ?? 'N/A' }}</td>
<td>
<a href="{{ route('products.edit', $product) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('products.destroy', $product) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/products/create.blade.php -->
@extends('layouts.app')
@section('title', 'Create Product')
@section('content')
<h1>Create Product</h1>
<form action="{{ route('products.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Name" class="form-label">Name</label>
<input type="text" class="form-control" id="Name" name="Name" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description" required></textarea>
</div>
<div class="mb-3">
<label for="Price" class="form-label">Price</label>
<input type="number" step="0.01" class="form-control" id="Price" name="Price" required>
</div>
<div class="mb-3">
<label for="Stock" class="form-label">Stock</label>
<input type="number" class="form-control" id="Stock" name="Stock" required>
</div>
<div class="mb-3">
<label for="CategoryId" class="form-label">Category</label>
<select class="form-select" id="CategoryId" name="CategoryId">
<option value="">Select Category</option>
@foreach ($categories as $category)
<option value="{{ $category->CategoryId }}">{{ $category->Name }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create Product</button>
<a href="{{ route('products.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Edit View

<!-- resources/views/products/edit.blade.php -->
@extends('layouts.app')
@section('title', 'Edit Product')
@section('content')
<h1>Edit Product</h1>
<form action="{{ route('products.update', $product) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Name" class="form-label">Name</label>
<input type="text" class="form-control" id="Name" name="Name" value="{{ $product->Name }}" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description" required>{{ $product->Description }}</textarea>
</div>
<div class="mb-3">
<label for="Price" class="form-label">Price</label>
<input type="number" step="0.01" class="form-control" id="Price" name="Price" value="{{ $product->Price }}" required>
</div>
<div class="mb-3">
<label for="Stock" class="form-label">Stock</label>
<input type="number" class="form-control" id="Stock" name="Stock" value="{{ $product->Stock }}" required>
</div>
<div class="mb-3">
<label for="CategoryId" class="form-label">Category</label>
<select class="form-select" id="CategoryId" name="CategoryId">
<option value="">Select Category</option>
@foreach ($categories as $category)
<option value="{{ $category->CategoryId }}" {{ $product->CategoryId == $category->CategoryId ? 'selected' : '' }}>{{ $category->Name }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Update Product</button>
<a href="{{ route('products.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/products/show.blade.php -->
@extends('layouts.app')
@section('title', 'Product Details')
@section('content')
<h1>Product Details</h1>
<p><strong>Name:</strong> {{ $product->Name }}</p>
<p><strong>Description:</strong> {{ $product->Description }}</p>
<p><strong>Price:</strong> ${{ number_format($product->Price, 2) }}</p>
<p><strong>Stock:</strong> {{ $product->Stock }}</p>
<p><strong>Category:</strong> {{ $product->category->Name ?? 'N/A' }}</p>
<a href="{{ route('products.edit', $product) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('products.index') }}" class="btn btn-secondary">Back</a>
@endsection

Categories

Index View

<!-- resources/views/categories/index.blade.php -->
@extends('layouts.app')
@section('title', 'Categories')
@section('content')
<h1>Categories</h1>
<a href="{{ route('categories.create') }}" class="btn btn-primary mb-3">Create Category</a>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($categories as $category)
<tr>
<td>{{ $category->Name }}</td>
<td>
<a href="{{ route('categories.edit', $category) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('categories.destroy', $category) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/categories/create.blade.php -->
@extends('layouts.app')
@section('title', 'Create Category')
@section('content')
<h1>Create Category</h1>
<form action="{{ route('categories.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Name" class="form-label">Name</label>
<input type="text" class="form-control" id="Name" name="Name" required>
</div>
<button type="submit" class="btn btn-primary">Create Category</button>
<a href="{{ route('categories.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Edit View

<!-- resources/views/categories/edit.blade.php -->
@extends('layouts.app')
@section('title', 'Edit Category')
@section('content')
<h1>Edit Category</h1>
<form action="{{ route('categories.update', $category) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Name" class="form-label">Name</label>
<input type="text" class="form-control" id="Name" name="Name" value="{{ $category->Name }}" required>
</div>
<button type="submit" class="btn btn-primary">Update Category</button>
<a href="{{ route('categories.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/categories/show.blade.php -->
@extends('layouts.app')
@section('title', 'Category Details')
@section('content')
<h1>Category Details</h1>
<p><strong>Name:</strong> {{ $category->Name }}</p>
<a href="{{ route('categories.edit', $category) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('categories.index') }}" class="btn btn-secondary">Back</a>
@endsection

Cart Items

Index View

<!-- resources/views/cart_items/index.blade.php -->
@extends('layouts.app')
@section('title', 'Cart Items')
@section('content')
<h1>Cart Items</h1>
<table class="table">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($cartItems as $cartItem)
<tr>
<td>{{ $cartItem->product->Name }}</td>
<td>{{ $cartItem->Quantity }}</td>
<td>
<form action="{{ route('cart_items.destroy', $cartItem) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Remove</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

Orders

Index View

<!-- resources/views/orders/index.blade.php -->
@extends('layouts.app')
@section('title', 'Orders')
@section('content')
<h1>Orders</h1>
<table class="table">
<thead>
<tr>
<th>Order ID</th>
<th>User</th>
<th>Total Amount</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($orders as $order)
<tr>
<td>{{ $order->OrderId }}</td>
<td>{{ $order->user->Username }}</td>
<td>${{ number_format($order->TotalAmount, 2) }}</td>
<td>{{ $order->Status }}</td>
<td>
<a href="{{ route('orders.show', $order) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/orders/create.blade.php -->
@extends('layouts.app')
@section('title', 'Create Order')
@section('content')
<h1>Create Order</h1>
<form action="{{ route('orders.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach ($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create Order</button>
<a href="{{ route('orders.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/orders/show.blade.php -->
@extends('layouts.app')
@section('title', 'Order Details')
@section('content')
<h1>Order Details</h1>
<p><strong>Order ID:</strong> {{ $order->OrderId }}</p>
<p><strong>User:</strong> {{ $order->user->Username }}</p>
<p><strong>Total Amount:</strong> ${{ number_format($order->TotalAmount, 2) }}</p>
<p><strong>Status:</strong> {{ $order->Status }}</p>
<a href="{{ route('orders.index') }}" class="btn btn-secondary">Back</a>
@endsection

Order Items

Index View

<!-- resources/views/order_items/index.blade.php -->
@extends('layouts.app')
@section('title', 'Order Items')
@section('content')
<h1>Order Items</h1>
<table class="table">
<thead>
<tr>
<th>Order ID</th>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
@foreach ($orderItems as $orderItem)
<tr>
<td>{{ $orderItem->order->OrderId }}</td>
<td>{{ $orderItem->product->Name }}</td>
<td>{{ $orderItem->Quantity }}</td>
<td>${{ number_format($orderItem->Price, 2) }}</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

Reviews

Index View

<!-- resources/views/reviews/index.blade.php -->
@extends('layouts.app')
@section('title', 'Reviews')
@section('content')
<h1>Reviews</h1>
<table class="table">
<thead>
<tr>
<th>Product</th>
<th>User</th>
<th>Rating</th>
<th>Comment</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($reviews as $review)
<tr>
<td>{{ $review->product->Name }}</td>
<td>{{ $review->user->Username }}</td>
<td>{{ $review->Rating }}</td>
<td>{{ $review->Comment }}</td>
<td>
<a href="{{ route('reviews.edit', $review) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('reviews.destroy', $review) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/reviews/create.blade.php -->
@extends('layouts.app')
@section('title', 'Create Review')
@section('content')
<h1>Create Review</h1>
<form action="{{ route('reviews.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="ProductId" class="form-label">Product</label>
<select class="form-select" id="ProductId" name="ProductId">
<option value="">Select Product</option>
@foreach ($products as $product)
<option value="{{ $product->ProductId }}">{{ $product->Name }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach ($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Rating" class="form-label">Rating</label>
<input type="number" class="form-control" id="Rating" name="Rating" min="1" max="5" required>
</div>
<div class="mb-3">
<label for="Comment" class="form-label">Comment</label>
<textarea class="form-control" id="Comment" name="Comment" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Create Review</button>
<a href="{{ route('reviews.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Edit View

<!-- resources/views/reviews/edit.blade.php -->
@extends('layouts.app')
@section('title', 'Edit Review')
@section('content')
<h1>Edit Review</h1>
<form action="{{ route('reviews.update', $review) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="ProductId" class="form-label">Product</label>
<select class="form-select" id="ProductId" name="ProductId">
<option value="">Select Product</option>
@foreach ($products as $product)
<option value="{{ $product->ProductId }}" {{ $review->ProductId == $product->ProductId ? 'selected' : '' }}>{{ $product->Name }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach ($users as $user)
<option value="{{ $user->User Id }}" {{ $review->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Rating" class="form-label">Rating</label>
<input type="number" class="form-control" id="Rating" name="Rating" value="{{ $review->Rating }}" min="1" max="5" required>
</div>
<div class="mb-3">
<label for="Comment" class="form-label">Comment</label>
<textarea class="form-control" id="Comment" name="Comment" required>{{ $review->Comment }}</textarea>
</div>
<button type="submit" class="btn btn-primary">Update Review</button>
<a href="{{ route('reviews.index') }}" class="btn btn -secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/reviews/show.blade.php -->
@extends('layouts.app')
@section('title', 'Review Details')
@section('content')
<h1>Review Details</h1>
<p><strong>Product:</strong> {{ $review->product->Name }}</p>
<p><strong>User:</strong> {{ $review->user->Username }}</p>
<p><strong>Rating:</strong> {{ $review->Rating }}</p>
<p><strong>Comment:</strong> {{ $review->Comment }}</p>
<a href="{{ route('reviews.edit', $review) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('reviews.index') }}" class="btn btn-secondary">Back</a>
@endsection

Wishlists

Index View

<!-- resources/views/wishlists/index.blade.php -->
@extends('layouts.app')
@section('title', 'Wishlists')
@section('content')
<h1>Wishlists</h1>
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($wishlists as $wishlist)
<tr>
<td>{{ $wishlist->user->Username }}</td>
<td>
<a href="{{ route('wishlists.show', $wishlist) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/wishlists/create.blade.php -->
@extends('layouts.app')
@section('title', 'Create Wishlist')
@section('content')
<h1>Create Wishlist</h1>
<form action="{{ route('wishlists.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach ($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create Wishlist</button>
<a href="{{ route('wishlists.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/wishlists/show.blade.php -->
@extends('layouts.app')
@section('title', 'Wishlist Details')
@section('content')
<h1>Wishlist Details</h1>
<p><strong>User:</strong> {{ $wishlist->user->Username }}</p>
<h2>Items</h2>
<ul>
@foreach ($wishlist->items as $item)
<li>{{ $item->product->Name }}</li>
@endforeach
</ul>
<a href="{{ route('wishlists.index') }}" class="btn btn-secondary">Back</a>
@endsection

Wishlist Items

Index View

<!-- resources/views/wishlist_items/index.blade.php -->
@extends('layouts.app')
@section('title', 'Wishlist Items')
@section('content')
<h1>Wishlist Items</h1>
<table class="table">
<thead>
<tr>
<th>Wishlist</th>
<th>Product</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($wishlistItems as $wishlistItem)
<tr>
<td>{{ $wishlistItem->wishlist->user->Username }}</td>
<td>{{ $wishlistItem->product->Name }}</td>
<td>
<form action="{{ route('wishlist_items.destroy', $wishlistItem) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Remove</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

Coupons

Index View

<!-- resources/views/coupons/index.blade.php -->
@extends('layouts.app')
@section('title', 'Coupons')
@section('content')
<h1>Coupons</h1>
<a href="{{ route('coupons.create') }}" class="btn btn-primary mb-3">Create Coupon</a>
<table class="table">
<thead>
<tr>
<th>Code</th>
<th>Discount</th>
<th>Expiration Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($coupons as $coupon)
<tr>
<td>{{ $coupon->Code }}</td>
<td>{{ $coupon->Discount }}%</td>
<td>{{ $coupon->ExpirationDate->format('Y-m-d') }}</td>
<td>
<a href="{{ route('coupons.edit', $coupon) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('coupons.destroy', $coupon) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/coupons/create.blade.php -->
@extends('layouts.app')
@section('title', 'Create Coupon')
@section('content')
<h1>Create Coupon</h1>
<form action="{{ route('coupons.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Code" class="form-label">Coupon Code</label>
<input type="text" class="form-control" id="Code" name="Code" required>
</div>
<div class="mb-3">
<label for="Discount" class="form-label">Discount (%)</label>
<input type="number" class="form-control" id="Discount" name="Discount" min="0" max="100" required>
</div>
<div class="mb-3">
<label for="ExpirationDate" class="form-label">Expiration Date</label>
<input type="date" class="form-control" id="ExpirationDate" name="ExpirationDate" required>
</div>
<button type="submit" class="btn btn-primary">Create Coupon</button>
<a href="{{ route('coupons.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Edit View

<!-- resources/views/coupons/edit.blade.php -->
@extends('layouts.app')
@section('title', 'Edit Coupon')
@section('content')
<h1>Edit Coupon</h1>
<form action="{{ route('coupons.update', $coupon) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Code" class="form-label">Coupon Code</label>
<input type="text" class="form-control" id="Code" name="Code" value="{{ $coupon->Code }}" required>
</div>
<div class="mb-3">
<label for="Discount" class="form-label">Discount (%)</label>
<input type="number" class="form-control" id="Discount" name="Discount" value="{{ $coupon->Discount }}" min="0" max="100" required>
</div>
<div class="mb-3">
<label for="ExpirationDate" class="form-label">Expiration Date</label>
<input type="date" class="form-control" id="ExpirationDate" name="ExpirationDate" value="{{ $coupon->ExpirationDate->format('Y-m-d') }}" required>
</div>
<button type="submit" class="btn btn-primary">Update Coupon</button>
<a href="{{ route('coupons.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/coupons/show.blade.php -->
@extends('layouts.app')
@section('title', 'Coupon Details')
@section('content')
<h1>Coupon Details</h1>
<p><strong>Code:</strong> {{ $coupon->Code }}</p>
<p><strong>Discount:</strong> {{ $coupon->Discount }}%</p>
<p><strong>Expiration Date:</strong> {{ $coupon->ExpirationDate->format('Y-m-d') }}</p>
<a href="{{ route('coupons.edit', $coupon) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('coupons.index') }}" class="btn btn-secondary">Back</a>
@endsection

Shipping Addresses

Index View

<!-- resources/views/shipping_addresses/index.blade.php -->
@extends('layouts.app')
@section('title', 'Shipping Addresses')
@section('content')
<h1>Shipping Addresses</h1>
<a href="{{ route('shipping_addresses.create') }}" class=" btn btn-primary mb-3">Add Shipping Address</a>
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($shippingAddresses as $address)
<tr>
<td>{{ $address->user->Username }}</td>
<td>{{ $address->Address }}</td>
<td>{{ $address->City }}</td>
<td>{{ $address->State }}</td>
<td>{{ $address->ZipCode }}</td>
<td>
<a href="{{ route('shipping_addresses.edit', $address) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('shipping_addresses.destroy', $address) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
Create View

<!-- resources/views/shipping_addresses/create.blade.php -->
@extends('layouts.app')
@section('title', 'Add Shipping Address')
@section('content')
<h1>Add Shipping Address</h1>
<form action="{{ route('shipping_addresses.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach ($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Address" class="form-label">Address</label>
<input type="text" class="form-control" id="Address" name="Address" required>
</div>
<div class="mb-3">
<label for="City" class="form-label">City</label>
<input type="text" class="form-control" id="City" name="City" required>
</div>
<div class="mb-3">
<label for="State" class="form-label">State</label>
<input type="text" class="form-control" id="State" name="State" required>
</div>
<div class="mb-3">
<label for="ZipCode" class="form-label">Zip Code</label>
<input type="text" class="form-control" id="ZipCode" name="ZipCode" required>
</div>
<button type="submit" class="btn btn-primary">Add Address</button>
<a href="{{ route('shipping_addresses.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Edit View

<!-- resources/views/shipping_addresses/edit.blade.php -->
@extends('layouts.app')
@section('title', 'Edit Shipping Address')
@section('content')
<h1>Edit Shipping Address</h1>
<form action="{{ route('shipping_addresses.update', $address) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach ($users as $user)
<option value="{{ $user->User Id }}" {{ $address->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Address" class="form-label">Address</label>
<input type="text" class="form-control" id="Address" name="Address" value="{{ $address->Address }}" required>
</div>
<div class="mb-3">
<label for="City" class="form-label">City</label>
<input type="text" class="form-control" id="City" name="City" value="{{ $address->City }}" required>
</div>
<div class="mb-3">
<label for="State" class="form-label">State</label>
<input type="text" class="form -control" id="State" name="State" value="{{ $address->State }}" required>
</div>
<div class="mb-3">
<label for="ZipCode" class="form-label">Zip Code</label>
<input type="text" class="form-control" id="ZipCode" name="ZipCode" value="{{ $address->ZipCode }}" required>
</div>
<button type="submit" class="btn btn-primary">Update Address</button>
<a href="{{ route('shipping_addresses.index') }}" class="btn btn-secondary">Back</a>
</form>
@endsection
Show View

<!-- resources/views/shipping_addresses/show.blade.php -->
@extends('layouts.app')
@section('title', 'Shipping Address Details')
@section('content')
<h1>Shipping Address Details</h1>
<p><strong>User:</strong> {{ $address->user->Username }}</p>
<p><strong>Address:</strong> {{ $address->Address }}</p>
<p><strong>City:</strong> {{ $address->City }}</p>
<p><strong>State:</strong> {{ $address->State }}</p>
<p><strong>Zip Code:</strong> {{ $address->ZipCode }}</p>
<a href="{{ route('shipping_addresses.edit', $address) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('shipping_addresses.index') }}" class="btn btn-secondary">Back</a>
@endsection

This completes the view files for all the specified models using Bootstrap 5. Each model has a consistent structure for CRUD operations, ensuring a user-friendly interface for managing data. You can further customize these views based on your application's specific requirements.

Creating a Shop Page

To create a shop page that displays products and includes an "Add to Cart" button for each product, you can follow these steps. Below, I will provide a simple implementation using Bootstrap 5.

Step 1: Create the Shop Page View

Create a new Blade view file named shop.blade.php in the resources/views directory.


<!-- resources/views/shop.blade.php -->
@extends('layouts.app')
@section('title', 'Shop')
@section('content')
<h1>Shop</h1>
<div class="row">
@foreach ($products as $product)
<div class="col-md-4 mb-4">
<div class="card">
<img src="https://via.placeholder.com/300" class="card-img-top" alt="{{ $product->Name }}">
<div class="card-body">
<h5 class="card-title">{{ $product->Name }}</h5>
<p class="card-text">{{ $product->Description }}</p>
<p class="card-text"><strong>Price:</strong> ${{ number_format($product->Price, 2) }}</p>
<form action="{{ route('cart_items.store') }}" method="POST">
@csrf
<input type="hidden" name="ProductId" value="{{ $product->ProductId }}">
<div class="mb-3">
<label for="Quantity{{ $product->ProductId }}" class="form-label">Quantity</label>
<input type="number" class="form-control" id="Quantity{{ $product->ProductId }}" name="Quantity" value="1" min="1" required>
</div>
<button type="submit" class="btn btn-primary">Add to Cart</button>
</form>
</div>
</div>
</div>
@endforeach
</div>
@endsection

Step 2: Define the Route

You need to define a route for the shop page in your routes/web.php file. This route will point to a controller method that retrieves the products from the database.


use App\Http\Controllers\ProductController;
Route::get('/shop', [ProductController::class, 'shop'])->name('shop');

Step 3: Implement the Controller Method

In your ProductController, add a method to retrieve the products and return the shop view.


// app/Http/Controllers/ProductController.php
public function shop()
{
$products = Product::all(); // Retrieve all products
return view('shop', compact('products'));
}

Step 4: Add Cart Functionality
Make sure you have a CartItemController with a method to handle adding items to the cart. Here’s a simple implementation of the store method in the CartItemController.

// app/Http/Controllers/CartItemController.php
public function store(Request $request)
{
$request->validate([
'ProductId' => 'required|exists:products,ProductId',
'Quantity' => 'required|integer|min:1',
]);
// Assuming you have a way to get the authenticated user
$userId = auth()->id();
// Check if the item already exists in the cart
$cartItem = CartItem::where('User Id', $userId)
->where('ProductId', $request->ProductId)
->first();
if ($cartItem) {
// If it exists, update the quantity
$cartItem->Quantity += $request->Quantity;
$cartItem->save();
} else {
// If it doesn't exist, create a new cart item
CartItem::create([
'User Id' => $userId,
'ProductId' => $request->ProductId,
'Quantity' => $request->Quantity,
]);
}
return redirect()->route('shop')->with('success', 'Product added to cart successfully.');
}

Step 5: Update the Layout for Notifications

Make sure your layout file (app.blade.php) can display success messages. You can add the following code snippet to the top of the body section:


@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif

Step 6: Test the Shop Page

Now, you can navigate to /shop in your application, and you should see a list of products with an "Add to Cart" button for each product. When you click the button, the product will be added to the cart, and you will see a success message.

Creating a Dashboard Page

To create a dashboard page that displays consolidated data related to your project, you can follow these steps. The dashboard can include various statistics such as the total number of users, products, orders, reviews, and any other relevant metrics.

Step 1: Create the Dashboard View

Create a new Blade view file named dashboard.blade.php in the resources/views directory.


<!-- resources/views/dashboard.blade.php -->
@extends('layouts.app')
@section('title', 'Dashboard')
@section('content')
<h1>Dashboard</h1>
<div class="row">
<div class="col-md-3 mb-4">
<div class="card text-white bg-primary">
<div class="card-body">
<h5 class="card-title">Total Users</h5>
<p class="card-text">{{ $totalUsers }}</p>
</div>
</div>
</div>
<div class="col-md-3 mb-4">
<div class="card text-white bg-success">
<div class="card-body">
<h5 class="card-title">Total Products</h5>
<p class="card-text">{{ $totalProducts }}</p>
</div>
</div>
</div>
<div class="col-md-3 mb-4">
<div class="card text-white bg-warning">
<div class="card-body">
<h5 class="card-title">Total Orders</h5>
<p class="card-text">{{ $totalOrders }}</p>
</div>
</div>
</div>
<div class="col-md-3 mb-4">
<div class="card text-white bg-danger">
<div class="card-body">
<h5 class="card-title">Total Reviews</h5>
<p class="card-text">{{ $totalReviews }}</p>
</div>
</div>
</div>
</div>
<h2>Recent Orders</h2>
<table class="table">
<thead>
<tr>
<th>Order ID</th>
<th>User</th>
<th>Total Amount</th>
<th>Status</th>
<th>Order Date</th>
</tr>
</thead>
<tbody>
@foreach ($recentOrders as $order)
<tr>
<td>{{ $order->OrderId }}</td>
<td>{{ $order->user->Username }}</td>
<td>${{ number_format($order->TotalAmount, 2) }}</td>
<td>{{ $order->Status }}</td>
<td>{{ $order->OrderDate->format('Y-m-d') }}</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

Step 2: Define the Route

You need to define a route for the dashboard page in your routes/web.php file. This route will point to a controller method that retrieves the necessary data.


use App\Http\Controllers\DashboardController;
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

Step 3: Create the Dashboard Controller

Create a new controller named DashboardController using the Artisan command:


php artisan make:controller DashboardController

Then, implement the index method in the DashboardController to retrieve the necessary data.


// app/Http/Controllers/DashboardController.php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Product;
use App\Models\Order;
use App\Models\Review;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function index()
{
$totalUsers = User::count();
$totalProducts = Product::count();
$totalOrders = Order::count();
$totalReviews = Review::count();
$recentOrders = Order::with('user')->orderBy('OrderDate', 'desc')->take(5)->get();
return view('dashboard', compact('totalUsers', 'totalProducts', 'totalOrders', 'totalReviews', 'recentOrders'));
}
}

Step 4: Update the Layout for Notifications

Make sure your layout file (app.blade.php) can display success messages. You can add the following code snippet to the top of the body section:


@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif

Step 5: Test the Dashboard Page

Now, you can navigate to /dashboard in your application, and you should see a dashboard displaying the total number of users, products, orders, reviews, and a table of recent orders.