Day 1 – Setting Up the AI Product Recommendation Engine #LaravelGPT #ProductRecommendation #AIRecommender #GPTFunctionCalling #LaravelAI


In this series, we’ll build an AI-powered Product Recommendation Engine using Laravel + GPT, where suggestions are generated based on user behavior and product metadata using function calling and optionally embeddings.


⚙️ Step 1: Create a fresh Laravel project

composer create-project laravel/laravel gpt-recommender
cd gpt-recommender

🛒 Step 2: Create Product and User models

php artisan make:model Product -m
php artisan make:model User -m
php artisan make:migration create_user_product_views_table

Update the migrations:

create_products_table.php:

public function up()
{
    Schema::create('products', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->text('description')->nullable();
        $table->decimal('price', 10, 2);
        $table->string('category')->nullable();
        $table->timestamps();
    });
}

create_users_table.php (if not default):

Ensure it has at least:

$table->string('name');
$table->string('email')->unique();

create_user_product_views_table.php:

public function up()
{
    Schema::create('user_product_views', function (Blueprint $table) {
        $table->id();
        $table->foreignId('user_id')->constrained()->onDelete('cascade');
        $table->foreignId('product_id')->constrained()->onDelete('cascade');
        $table->timestamp('viewed_at')->default(now());
    });
}

Run migrations:

php artisan migrate

📦 Step 3: Seed some dummy products

php artisan make:seeder ProductSeeder

In ProductSeeder.php:

use App\Models\Product;

public function run(): void
{
    $products = [
        ['name' => 'Wireless Headphones', 'description' => 'Bluetooth, noise-cancelling', 'price' => 299.00, 'category' => 'Electronics'],
        ['name' => 'Ergonomic Chair', 'description' => 'For office comfort', 'price' => 499.00, 'category' => 'Furniture'],
        ['name' => 'Smartwatch', 'description' => 'Fitness tracker & notifications', 'price' => 399.00, 'category' => 'Electronics'],
        ['name' => 'Standing Desk', 'description' => 'Adjustable height, wood top', 'price' => 999.00, 'category' => 'Furniture'],
    ];

    foreach ($products as $product) {
        Product::create($product);
    }
}

In DatabaseSeeder.php:

$this->call(ProductSeeder::class);

Seed the database:

php artisan db:seed

✅ Output

You now have:

  • A products table with items to recommend
  • A user_product_views table to track interest
  • The basic structure for connecting user behavior to GPT
See also  Day 8 – Ask GPT: “What Changed Yesterday?” Using Natural Language#LaravelGPTAudit #AIAssistant #NaturalLanguageAudit #GPTFunctionCalling #LaravelLogs

✅ Up next (Day 2): we’ll track user views, then use GPT function calling to suggest related products based on their view history.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.