-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add categories for lists (#52)
- Loading branch information
Showing
11 changed files
with
201 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class ListCategory extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'list_categories'; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'description', | ||
'is_serious', | ||
]; | ||
|
||
protected $casts = [ | ||
'is_serious' => 'boolean', | ||
]; | ||
|
||
public function nameLists(): HasMany | ||
{ | ||
return $this->hasMany(NameList::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ListCategory> | ||
*/ | ||
class ListCategoryFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'name' => fake()->name(), | ||
'description' => fake()->text(), | ||
'is_serious' => fake()->boolean, | ||
]; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
database/migrations/2024_02_19_131442_create_list_categories_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('list_categories', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->text('description')->nullable(); | ||
$table->boolean('is_serious')->default(true); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::table('lists', function (Blueprint $table) { | ||
$table->unsignedBigInteger('list_category_id')->after('user_id')->nullable(); | ||
$table->foreign('list_category_id')->references('id')->on('list_categories')->onDelete('cascade'); | ||
}); | ||
|
||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms d\'origine religieuse', | ||
'description' => 'En quête d\'un prénom empreint de spiritualité et d\'histoire ? Laissez-vous guider par notre sélection de prénoms d\'origine religieuse ! Des prénoms bibliques aux noms inspirés des grandes figures spirituelles, découvrez une source d\'inspiration infinie pour trouver le prénom parfait pour votre petit trésor.', | ||
'is_serious' => true, | ||
]); | ||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms d\'origine géographique', | ||
'description' => 'Partez à l\'aventure avec notre sélection de prénoms d\'origine géographique ! Des noms évoquant des paysages grandioses aux prénoms inspirés des plus belles villes du monde, découvrez une source d\'inspiration inédite pour trouver le prénom parfait pour votre petit explorateur.', | ||
'is_serious' => true, | ||
]); | ||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms d\'origine historique', | ||
'description' => 'Donnez à votre enfant un prénom qui traverse les siècles avec notre sélection de prénoms d\'origine historique ! Des figures légendaires aux personnages illustres, découvrez une source d\'inspiration unique pour trouver le prénom parfait pour votre petit prince ou votre petite princesse.', | ||
'is_serious' => true, | ||
]); | ||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms inspirés de la nature', | ||
'description' => 'Célébrez la beauté et la puissance de la nature en choisissant un prénom inspiré de ses éléments pour votre enfant ! Des fleurs délicates aux arbres majestueux, en passant par les animaux fascinants et les forces élémentaires, découvrez une source d\'inspiration infinie pour trouver le prénom parfait pour votre petit être.', | ||
'is_serious' => true, | ||
]); | ||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms inspirés de la littérature et du cinéma', | ||
'description' => 'Donnez vie à vos personnages préférés en choisissant un prénom inspiré de la littérature et du cinéma pour votre enfant ! Des héros inoubliables aux héroïnes courageuses, en passant par les créatures fantastiques et les personnages attachants, découvrez une source d\'inspiration inédite pour trouver le prénom parfait pour votre petit bout de chou.', | ||
'is_serious' => true, | ||
]); | ||
|
||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms inventés', | ||
'description' => 'Laissez libre cours à votre imagination et explorez le monde infini des prénoms inventés pour trouver le nom parfait pour votre enfant ! Des jeux vidéo aux univers fictifs, en passant par les gourmandises et les jeux de mots, découvrez une source d\'inspiration inédite pour créer un prénom unique et original qui correspond à votre personnalité et à vos rêves.', | ||
'is_serious' => false, | ||
]); | ||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms à double sens', | ||
'description' => 'Ajoutez une touche d\'originalité et de mystère au prénom de votre enfant en choisissant un nom à double sens ! Des prénoms qui changent de genre aux noms qui cachent des messages cachés, découvrez une source d\'inspiration inédite pour trouver le prénom parfait pour votre petit être.', | ||
'is_serious' => false, | ||
]); | ||
DB::table('list_categories')->insert([ | ||
'name' => 'Prénoms de célébrités', | ||
'description' => 'Donnez à votre enfant le prénom d\'une célébrité que vous admirez pour lui transmettre votre passion et lui inspirer des valeurs de réussite, de talent et de persévérance ! Des acteurs légendaires aux chanteurs talentueux, en passant par les sportifs de haut niveau, découvrez une source d\'inspiration infinie pour trouver le prénom parfait pour votre petit bout de chou.', | ||
'is_serious' => false, | ||
]); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Models; | ||
|
||
use App\Models\ListCategory; | ||
use App\Models\NameList; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tests\TestCase; | ||
|
||
class ListCategoryTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function it_has_many_list_names(): void | ||
{ | ||
$listCategory = ListCategory::factory()->create(); | ||
$nameList = NameList::factory()->create([ | ||
'list_category_id' => $listCategory->id, | ||
]); | ||
|
||
$this->assertTrue($listCategory->nameLists()->exists()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters