Skip to content

Commit 0033e5d

Browse files
committed
Add models and respective factories to seed the DB
1 parent ffc30f9 commit 0033e5d

31 files changed

+464
-34
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/laravel-idea.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/laravel-vue-showcase.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Based on [Laravel + Vue Starter Kit](https://github.com/laravel/vue-starter-kit)
55
## Instructions
66

77
### Developing with NixOS
8+
89
This project was developed using NixOS and a development environment was setup.
910
It can be activated by running `nix develop` in the project directory.
1011

@@ -29,6 +30,9 @@ php artisan key:generate
2930
# Database migrations
3031
php artisan migrate
3132

33+
# Seed the database
34+
php artisan seed
35+
3236
# Build the frontend
3337
npm build
3438

app/Models/Animal.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Database\Eloquent\Relations\HasMany;
9+
10+
class Animal extends Model
11+
{
12+
use HasFactory;
13+
14+
protected $fillable = [
15+
'name',
16+
'type',
17+
];
18+
19+
public function client(): BelongsTo
20+
{
21+
return $this->belongsTo(Client::class);
22+
}
23+
24+
public function appointments(): HasMany
25+
{
26+
return $this->hasMany(Appointment::class);
27+
}
28+
}

app/Models/Appointment.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
9+
class Appointment extends Model
10+
{
11+
use HasFactory;
12+
13+
protected $fillable = [
14+
'symptoms',
15+
'preferred_date',
16+
'preferred_time',
17+
'animal_age_months',
18+
];
19+
20+
protected $casts = [
21+
'assigned_at' => 'timestamp',
22+
];
23+
24+
public function animal(): BelongsTo
25+
{
26+
return $this->belongsTo(Animal::class);
27+
}
28+
29+
public function receptionist(): BelongsTo
30+
{
31+
return $this->belongsTo(User::class, 'receptionist_id');
32+
}
33+
34+
public function medic(): BelongsTo
35+
{
36+
return $this->belongsTo(User::class, 'medic_id');
37+
}
38+
}

app/Models/Client.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\HasMany;
8+
use Illuminate\Notifications\Notifiable;
9+
10+
class Client extends Model
11+
{
12+
use HasFactory, Notifiable;
13+
14+
protected $fillable = [
15+
'name',
16+
'email',
17+
];
18+
19+
public function animals(): HasMany
20+
{
21+
return $this->hasMany(Animal::class);
22+
}
23+
}

app/Models/User.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,44 @@
22

33
namespace App\Models;
44

5-
// use Illuminate\Contracts\Auth\MustVerifyEmail;
5+
use App\UserType;
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Database\Eloquent\Relations\HasMany;
78
use Illuminate\Foundation\Auth\User as Authenticatable;
89
use Illuminate\Notifications\Notifiable;
910

1011
class User extends Authenticatable
1112
{
12-
/** @use HasFactory<\Database\Factories\UserFactory> */
1313
use HasFactory, Notifiable;
1414

15-
/**
16-
* The attributes that are mass assignable.
17-
*
18-
* @var list<string>
19-
*/
2015
protected $fillable = [
2116
'name',
2217
'email',
2318
'password',
19+
'type',
2420
];
2521

26-
/**
27-
* The attributes that should be hidden for serialization.
28-
*
29-
* @var list<string>
30-
*/
3122
protected $hidden = [
3223
'password',
3324
'remember_token',
3425
];
3526

36-
/**
37-
* Get the attributes that should be cast.
38-
*
39-
* @return array<string, string>
40-
*/
4127
protected function casts(): array
4228
{
4329
return [
4430
'email_verified_at' => 'datetime',
4531
'password' => 'hashed',
32+
'type' => UserType::class,
4633
];
4734
}
35+
36+
public function medicAppointments(): HasMany
37+
{
38+
return $this->hasMany(Appointment::class, 'medic_id');
39+
}
40+
41+
public function receptionistAppointments(): HasMany
42+
{
43+
return $this->hasMany(Appointment::class, 'receptionist_id');
44+
}
4845
}

app/TimeOfDay.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App;
4+
5+
enum TimeOfDay: string
6+
{
7+
case Morning = 'morning';
8+
case Afternoon = 'afternoon';
9+
case AllDay = 'all_day';
10+
}

0 commit comments

Comments
 (0)