feat: add SocialAccount model, migration, and factory

Implement SocialAccount model with enum fields for network and type,
along with migration and factory. Includes NETWORKS and TYPES constants
for dropdown usage in Livewire forms and validation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-07-18 14:50:00 +03:00
co-authored by Claude Sonnet 5
parent 889ac9b7f9
commit 137a15f5ff
4 changed files with 111 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SocialAccount extends Model
{
use HasFactory;
public const NETWORKS = [
'twitter', 'instagram', 'facebook', 'reddit',
'tiktok', 'linkedin', 'youtube', 'other',
];
public const TYPES = ['post', 'comment', 'like'];
protected $fillable = [
'network',
'username',
'email',
'password',
'type',
];
}
@@ -0,0 +1,22 @@
<?php
namespace Database\Factories;
use App\Models\SocialAccount;
use Illuminate\Database\Eloquent\Factories\Factory;
class SocialAccountFactory extends Factory
{
protected $model = SocialAccount::class;
public function definition(): array
{
return [
'network' => fake()->randomElement(SocialAccount::NETWORKS),
'username' => fake()->userName(),
'email' => fake()->safeEmail(),
'password' => fake()->password(),
'type' => fake()->optional()->randomElement(SocialAccount::TYPES),
];
}
}
@@ -0,0 +1,32 @@
<?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('social_accounts', function (Blueprint $table) {
$table->id();
$table->enum('network', [
'twitter', 'instagram', 'facebook', 'reddit',
'tiktok', 'linkedin', 'youtube', 'other',
]);
$table->string('username');
$table->string('email');
$table->string('password');
$table->enum('type', ['post', 'comment', 'like'])->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('social_accounts');
}
};
+31
View File
@@ -0,0 +1,31 @@
<?php
use App\Models\SocialAccount;
test('a social account can be created with all required fields and a type', function () {
$account = SocialAccount::create([
'network' => 'twitter',
'username' => 'my_handle',
'email' => 'handle@example.com',
'password' => 'plain-text-password',
'type' => 'post',
]);
expect($account->fresh())
->network->toBe('twitter')
->username->toBe('my_handle')
->email->toBe('handle@example.com')
->password->toBe('plain-text-password')
->type->toBe('post');
});
test('a social account can be created with a null type', function () {
$account = SocialAccount::create([
'network' => 'instagram',
'username' => 'my_handle',
'email' => 'handle@example.com',
'password' => 'plain-text-password',
]);
expect($account->fresh()->type)->toBeNull();
});