From 1c26a7801c80ac9688be5b7dbc20560e3b6385e9 Mon Sep 17 00:00:00 2001 From: Alyx Batte Date: Mon, 24 Nov 2025 09:51:00 -0500 Subject: [PATCH] feat: add basic specimen functionality --- app/Livewire/Forms/SpecimenForm.php | 105 ++++++++++++++++++ app/Livewire/Herbarium/CreateSpecimen.php | 23 ++++ app/Models/Specimen.php | 42 ++++++- app/Models/User.php | 6 + app/View/Components/Forms/textInput.php | 26 +++++ .../components/layouts/app/sidebar.blade.php | 4 + .../layouts/specimen/layout.blade.php | 5 + routes/web.php | 5 + 8 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 app/Livewire/Forms/SpecimenForm.php create mode 100644 app/Livewire/Herbarium/CreateSpecimen.php create mode 100644 app/View/Components/Forms/textInput.php create mode 100644 resources/views/components/layouts/specimen/layout.blade.php diff --git a/app/Livewire/Forms/SpecimenForm.php b/app/Livewire/Forms/SpecimenForm.php new file mode 100644 index 0000000..446352c --- /dev/null +++ b/app/Livewire/Forms/SpecimenForm.php @@ -0,0 +1,105 @@ +validate(); + + Specimen::create($this->only([ + 'date', + 'family', + 'genus', + 'specificEpithet', + 'collector', + 'collectionNumber', + 'associateCollectors', + 'plantHabit', + 'populationSize', + 'substrate', + 'phenologyFlowering', + 'phenologyFruiting', + 'phenologyFruitingFlowering', + 'phenologyVegetative', + 'phenologyNotes', + 'vegetationCommunity', + 'plantAssociates', + 'aspect', + 'exposure', + 'elevation', + 'location', + 'latitude', + 'longitude', + ])); + } +} diff --git a/app/Livewire/Herbarium/CreateSpecimen.php b/app/Livewire/Herbarium/CreateSpecimen.php new file mode 100644 index 0000000..7f9cc22 --- /dev/null +++ b/app/Livewire/Herbarium/CreateSpecimen.php @@ -0,0 +1,23 @@ +form->store(); + + return $this->redirect('/herbarium/list'); + } +} diff --git a/app/Models/Specimen.php b/app/Models/Specimen.php index d8d5099..1a26dd2 100644 --- a/app/Models/Specimen.php +++ b/app/Models/Specimen.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasOne; class Specimen extends Model { @@ -13,6 +14,43 @@ class Specimen extends Model protected $table = 'specimens'; protected $fillable = [ - '' - ] + 'date', + 'family', + 'genus', + 'specific_epithet', + 'collector', + 'collection_number', + 'associate_collectors', + 'plant_habit', // herb, vine, shrub, liana, shrub, subshrub, tree + 'population_size', + 'substrate', + 'phenology_flowering', + 'phenology_fruiting', + 'phenology_fruiting_flowering', + 'phenology_notes', + 'phenology_vegetative', + 'vegetation_community', + 'plant_associates', + 'aspect', + 'exposure', + 'elevation', + 'location', + 'latitude', + 'longitude', + 'user_id', + ]; + + public function user(): HasOne + { + return $this->hasOne(User::class,'id','user_id'); + } + + protected function casts(): array + { + return [ + 'date' => 'date', + 'associate_collectors' => 'array', + 'plant_associates' => 'array', + ]; + } } diff --git a/app/Models/User.php b/app/Models/User.php index 214bea4..47a6c3a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,7 @@ // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Str; @@ -37,6 +38,11 @@ class User extends Authenticatable 'remember_token', ]; + public function specimens(): HasMany + { + return $this->hasMany(Specimen::class); + } + /** * Get the attributes that should be cast. * diff --git a/app/View/Components/Forms/textInput.php b/app/View/Components/Forms/textInput.php new file mode 100644 index 0000000..cd5bfff --- /dev/null +++ b/app/View/Components/Forms/textInput.php @@ -0,0 +1,26 @@ + {{ __('Dashboard') }} + + + {{ __('Add New') }} + diff --git a/resources/views/components/layouts/specimen/layout.blade.php b/resources/views/components/layouts/specimen/layout.blade.php new file mode 100644 index 0000000..22a89ed --- /dev/null +++ b/resources/views/components/layouts/specimen/layout.blade.php @@ -0,0 +1,5 @@ +
+

Specimens - {{ $header }}

+ + {{ $slot }} +
diff --git a/routes/web.php b/routes/web.php index b2c5bc5..2811c93 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ name('two-factor.show'); }); + +Route::middleware(['auth', 'verified'])->group(function () { + Route::get('specimens/create', CreateSpecimen::class)->name('specimen.create'); +});