diff --git a/app/Http/Controllers/GoalController.php b/app/Http/Controllers/GoalController.php index d7a5e8b..8e176f5 100644 --- a/app/Http/Controllers/GoalController.php +++ b/app/Http/Controllers/GoalController.php @@ -51,7 +51,7 @@ class GoalController extends Controller { return view('goals.edit') ->with('goal', $goal) - ->with('attributeOptions', Goal::getAttributeOptions()); + ->with('goalOptions', Goal::getGoalOptions()); } /** @@ -62,8 +62,8 @@ class GoalController extends Controller $attributes = $request->validate([ 'from' => ['nullable', 'date'], 'to' => ['nullable', 'date'], - 'attribute' => ['required', 'string'], - 'goal' => ['required', 'numeric'], + 'goal' => ['required', 'string'], + 'amount' => ['required', 'numeric'], ]); $goal->fill(array_filter($attributes)) ->user()->associate(Auth::user()); diff --git a/app/Models/Goal.php b/app/Models/Goal.php index 6f4c8d7..fd21454 100644 --- a/app/Models/Goal.php +++ b/app/Models/Goal.php @@ -6,7 +6,6 @@ use App\Support\Nutrients; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Support\Str; /** * App\Models\Goal @@ -15,15 +14,15 @@ use Illuminate\Support\Str; * @property int $user_id * @property \datetime|null $from * @property \datetime|null $to - * @property string $attribute - * @property float $goal + * @property string $goal + * @property float $amount * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property-read \App\Models\User $user * @method static \Illuminate\Database\Eloquent\Builder|Goal newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Goal newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Goal query() - * @method static \Illuminate\Database\Eloquent\Builder|Goal whereAttribute($value) + * @method static \Illuminate\Database\Eloquent\Builder|Goal whereAmount($value) * @method static \Illuminate\Database\Eloquent\Builder|Goal whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Goal whereFrom($value) * @method static \Illuminate\Database\Eloquent\Builder|Goal whereGoal($value) @@ -33,7 +32,7 @@ use Illuminate\Support\Str; * @method static \Illuminate\Database\Eloquent\Builder|Goal whereUserId($value) * @mixin \Eloquent */ -class Goal extends Model +final class Goal extends Model { use HasFactory; @@ -43,8 +42,8 @@ class Goal extends Model protected $fillable = [ 'from', 'to', - 'attribute', 'goal', + 'amount', ]; /** @@ -53,7 +52,7 @@ class Goal extends Model protected $casts = [ 'from' => 'datetime:Y-m-d', 'to' => 'datetime:Y-m-d', - 'goal' => 'float', + 'amount' => 'float', ]; /** @@ -64,20 +63,18 @@ class Goal extends Model } /** - * Get options for the "attribute" column. + * Get options for the "goal" column. * * @return array */ - public static function getAttributeOptions(): array { + public static function getGoalOptions(): array { $options = []; foreach (Nutrients::$all as $nutrient) { - foreach (['daily', 'weekly', 'monthly', 'yearly'] as $frequency) { - $key = "{$nutrient['value']}_{$frequency}"; - $options[$key] = [ - 'value' => $key, - 'label' => Str::ucfirst("{$frequency} {$nutrient['value']}") - ]; - } + $key = "{$nutrient['value']}_per_day"; + $options[$key] = [ + 'value' => $key, + 'label' => "{$nutrient['value']} per day", + ]; } return $options; } diff --git a/database/migrations/2021_02_13_052427_create_goals_table.php b/database/migrations/2021_02_13_052427_create_goals_table.php index e3bd190..c2a73fd 100644 --- a/database/migrations/2021_02_13_052427_create_goals_table.php +++ b/database/migrations/2021_02_13_052427_create_goals_table.php @@ -19,8 +19,8 @@ class CreateGoalsTable extends Migration $table->foreignIdFor(User::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete(); $table->date('from')->nullable(); $table->date('to')->nullable(); - $table->string('attribute'); - $table->unsignedFloat('goal'); + $table->string('goal'); + $table->unsignedFloat('amount'); $table->timestamps(); $table->index('user_id'); }); diff --git a/resources/views/goals/delete.blade.php b/resources/views/goals/delete.blade.php index 974c58f..096ac93 100644 --- a/resources/views/goals/delete.blade.php +++ b/resources/views/goals/delete.blade.php @@ -1,7 +1,7 @@

- Delete {{ $goal->attribute }} Goal? + Delete {{ $goal->goal }} goal?

@@ -13,7 +13,7 @@ @method('delete') @csrf
- Are you sure what to delete your {{ $goal->attribute }} goal? + Are you sure what to delete your {{ $goal->goal }} goal?
Yes, delete diff --git a/resources/views/goals/edit.blade.php b/resources/views/goals/edit.blade.php index f89fe6e..16f963d 100644 --- a/resources/views/goals/edit.blade.php +++ b/resources/views/goals/edit.blade.php @@ -32,27 +32,24 @@ :value="old('to', $goal->to)" /> - +
- - - - - + +
- - - + + +
diff --git a/resources/views/goals/index.blade.php b/resources/views/goals/index.blade.php index 0934b63..d58e6c6 100644 --- a/resources/views/goals/index.blade.php +++ b/resources/views/goals/index.blade.php @@ -1,7 +1,7 @@
-

Goals

+

{{ Auth::user()->name }}'s Goals