Models
In Laravel, a model is a way to interact with your database using PHP objects. It acts as a bridge between your application and the database.
In Laravel, a model is a way to interact with your database using PHP objects. It acts as a bridge between your application and the database.
What is a Model?
A model represents a table in your database. For example, if you have a users table, you create a User model to manage that table. It provides an easy way to perform operations like adding, updating, and retrieving records.
Eloquent ORM
Laravel uses Eloquent as its Object-Relational Mapping (ORM) tool. Eloquent makes it easy to interact with your database using an elegant and expressive syntax.
Defining a Model
To define a model in Laravel, you create a PHP class that extends Illuminate\Database\Eloquent\Model. Here’s a basic example:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
// The table associated with the model.
protected $table = 'users';
// The attributes that are mass assignable.
protected $fillable = ['name', 'email', 'password'];
}
E-Commerce API Models in Wham Services
In our e-com API, models are organized within the wham-services directory. Each service within this directory handles a specific domain of the e-com system and contains its own set of models.
Directory Structure
The models are organized by functional areas in the wham-services directory. Here’s how they are structured:
Overview of Each Service
- auth/: Contains models related to authentication and user management.
- content/: Includes models for managing and retrieving content.
- contracts-customers/: Models for handling customer contracts and related information.
- delivery-method/: Models for different delivery methods and logistics.
- catalog/: Models for product catalogs and related functionalities.
- notification/: Models for handling notifications and messaging.
- orders/: Models for managing orders, including order details and statuses.
- payments/: Models for payment processing and transaction handling.
- products/: Models related to product management, such as product details and inventory.
- stock/: Models for stock management and availability tracking.
- trolley/: Models for shopping cart or trolley functionalities.
- users/: Models related to user profiles and management. `