Skip to content

Commit

Permalink
Add user model, controller, factory, and migration for users and prod…
Browse files Browse the repository at this point in the history
…ucts
  • Loading branch information
ferjoaguilar committed Jan 16, 2025
1 parent a51ec5e commit 7fb57c7
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 50 deletions.
10 changes: 10 additions & 0 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UsersController extends Controller
{
//
}
12 changes: 12 additions & 0 deletions app/Models/Users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Users extends Model
{
/** @use HasFactory<\Database\Factories\UsersFactory> */
use HasFactory;
}
42 changes: 21 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions database/factories/UsersFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Users>
*/
class UsersFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->name(),
'lastname' => $this->faker->lastName(),
'email' => $this->faker->unique()->safeEmail(),
'password' => $this->faker->password(),
'phone' => $this->faker->phoneNumber(),
];
}
}
31 changes: 7 additions & 24 deletions database/migrations/0001_01_01_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,13 @@
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});

Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});

Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
$table->id(); // USERID INT AUTO_INCREMENT PRIMARY KEY
$table->string('name'); // NAME VARCHAR(255)
$table->string('lastname'); // LASTNAME VARCHAR(255)
$table->string('email')->unique(); // EMAIL VARCHAR(255) UNIQUE
$table->string('password'); // PASSWORD VARCHAR(255)
$table->string('phone')->nullable(); // PHONE VARCHAR(255) NULL
$table->timestamps(); // CREATED_AT TIMESTAMP, UPDATED_AT TIMESTAMP
});
}

Expand All @@ -43,7 +28,5 @@ public function up(): void
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};
27 changes: 27 additions & 0 deletions database/migrations/2025_01_15_011636_create_products_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('products');
}
};
9 changes: 4 additions & 5 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Database\Seeders;

use App\Models\User;
/* use App\Models\User; */

use App\Models\Users;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

Expand All @@ -15,9 +17,6 @@ public function run(): void
{
// User::factory(10)->create();

User::factory()->create([
'name' => 'Test User',
'email' => '[email protected]',
]);
Users::factory(250)->create();
}
}

0 comments on commit 7fb57c7

Please sign in to comment.