feat(models): add Country and NonWorkingDays models
This commit is contained in:
		
							parent
							
								
									5633ff78c6
								
							
						
					
					
						commit
						82f3ef39c9
					
				
							
								
								
									
										12
									
								
								app/Models/Country.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/Models/Country.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | declare(strict_types=1); | ||||||
|  | 
 | ||||||
|  | namespace App\Models; | ||||||
|  | 
 | ||||||
|  | use Illuminate\Database\Eloquent\Model; | ||||||
|  | 
 | ||||||
|  | class Country extends Model | ||||||
|  | { | ||||||
|  |     protected $fillable = ['country_code', 'name']; | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								app/Models/NonWorkingDays.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/Models/NonWorkingDays.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | declare(strict_types=1); | ||||||
|  | 
 | ||||||
|  | namespace App\Models; | ||||||
|  | 
 | ||||||
|  | use Illuminate\Database\Eloquent\Model; | ||||||
|  | 
 | ||||||
|  | class NonWorkingDays extends Model | ||||||
|  | { | ||||||
|  |     protected $fillable = ['country_id', 'non_working_date']; | ||||||
|  | } | ||||||
							
								
								
									
										29
									
								
								database/migrations/2024_08_04_172406_create_countries.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								database/migrations/2024_08_04_172406_create_countries.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | |||||||
|  | <?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('countries', function (Blueprint $table) { | ||||||
|  |             $table->id(); | ||||||
|  |             $table->string('name'); | ||||||
|  |             $table->string('country_code', 2)->unique(); | ||||||
|  |             $table->timestamps(); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Reverse the migrations. | ||||||
|  |      */ | ||||||
|  |     public function down(): void | ||||||
|  |     { | ||||||
|  |         Schema::dropIfExists('countries'); | ||||||
|  |     } | ||||||
|  | }; | ||||||
| @ -0,0 +1,31 @@ | |||||||
|  | <?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('non_working_days', function (Blueprint $table) { | ||||||
|  |             $table->id(); | ||||||
|  |             $table->unsignedBigInteger('country_id'); | ||||||
|  |             $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); | ||||||
|  |             $table->date('non_working_date'); | ||||||
|  |             $table->timestamps(); | ||||||
|  |             $table->unique(['country_id', 'non_working_date']); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Reverse the migrations. | ||||||
|  |      */ | ||||||
|  |     public function down(): void | ||||||
|  |     { | ||||||
|  |         Schema::dropIfExists('non_working_days'); | ||||||
|  |     } | ||||||
|  | }; | ||||||
							
								
								
									
										29
									
								
								database/seeders/CountrySeeder.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										29
									
								
								database/seeders/CountrySeeder.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,29 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace Database\Seeders; | ||||||
|  | 
 | ||||||
|  | use App\Models\Country; | ||||||
|  | use Illuminate\Database\Seeder; | ||||||
|  | use Illuminate\Database\UniqueConstraintViolationException; | ||||||
|  | 
 | ||||||
|  | class CountrySeeder extends Seeder | ||||||
|  | { | ||||||
|  |     private const array COUNTRIES = [ | ||||||
|  |         'CZ' => 'Czech Republic', | ||||||
|  |     ]; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Run the database seeds. | ||||||
|  |      */ | ||||||
|  |     public function run(): void | ||||||
|  |     { | ||||||
|  |         foreach (static::COUNTRIES as $countryCode => $countryName) { | ||||||
|  |             try { | ||||||
|  |                 Country::create(['country_code' => $countryCode, 'name' => $countryName]); | ||||||
|  |             } catch (UniqueConstraintViolationException $e) { | ||||||
|  |                 // safe to ignore duplicate entries
 | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         //
 | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user