From 6baf888d4f424dd930379d91376d9ed450a89678 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Wed, 27 Jan 2021 05:51:38 -0800 Subject: [PATCH] Add source and notes fields to foods --- app/Http/Controllers/FoodController.php | 2 ++ app/JsonApi/Schemas/FoodSchema.php | 2 ++ app/Models/Food.php | 6 ++++ .../2020_12_21_214128_create_foods_table.php | 2 ++ ...7_054520_add_source_and_notes_to_foods.php | 33 +++++++++++++++++++ resources/views/foods/edit.blade.php | 18 ++++++++++ 6 files changed, 63 insertions(+) create mode 100644 database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php diff --git a/app/Http/Controllers/FoodController.php b/app/Http/Controllers/FoodController.php index ffa7292..b55538f 100644 --- a/app/Http/Controllers/FoodController.php +++ b/app/Http/Controllers/FoodController.php @@ -72,6 +72,8 @@ class FoodController extends Controller 'name' => 'required|string', 'detail' => 'nullable|string', 'brand' => 'nullable|string', + 'source' => 'nullable|string', + 'notes' => 'nullable|string', 'serving_size' => ['required', new StringIsDecimalOrFraction], 'serving_unit' => 'nullable|string', 'serving_weight' => 'required|numeric', diff --git a/app/JsonApi/Schemas/FoodSchema.php b/app/JsonApi/Schemas/FoodSchema.php index a951c22..2fd35df 100644 --- a/app/JsonApi/Schemas/FoodSchema.php +++ b/app/JsonApi/Schemas/FoodSchema.php @@ -30,6 +30,8 @@ class FoodSchema extends SchemaProvider 'name' => $resource->name, 'detail' => $resource->detail, 'brand' => $resource->brand, + 'source' => $resource->source, + 'notes' => $resource->notes, 'calories' => $resource->calories, 'carbohydrates' => $resource->carbohydrates, 'cholesterol' => $resource->cholesterol, diff --git a/app/Models/Food.php b/app/Models/Food.php index cbf71e2..bfe7066 100644 --- a/app/Models/Food.php +++ b/app/Models/Food.php @@ -65,6 +65,10 @@ use Spatie\Tags\HasTags; * @method static \Illuminate\Database\Eloquent\Builder|Food withAllTagsOfAnyType($tags) * @method static \Illuminate\Database\Eloquent\Builder|Food withAnyTags($tags, ?string $type = null) * @method static \Illuminate\Database\Eloquent\Builder|Food withAnyTagsOfAnyType($tags) + * @property string|null $source + * @property string|null $notes + * @method static \Illuminate\Database\Eloquent\Builder|Food whereNotes($value) + * @method static \Illuminate\Database\Eloquent\Builder|Food whereSource($value) */ final class Food extends Model { @@ -82,6 +86,8 @@ final class Food extends Model 'name', 'detail', 'brand', + 'source', + 'notes', 'calories', 'carbohydrates', 'cholesterol', diff --git a/database/migrations/2020_12_21_214128_create_foods_table.php b/database/migrations/2020_12_21_214128_create_foods_table.php index 3f15e09..9c8cb75 100644 --- a/database/migrations/2020_12_21_214128_create_foods_table.php +++ b/database/migrations/2020_12_21_214128_create_foods_table.php @@ -17,6 +17,8 @@ class CreateFoodsTable extends Migration $table->string('slug')->unique(); $table->string('detail')->nullable(); $table->string('brand')->nullable(); + $table->string('source')->nullable(); + $table->string('notes')->nullable(); $table->unsignedFloat('serving_size'); $table->enum('serving_unit', ['tsp', 'tbsp', 'cup', 'oz'])->nullable(); $table->unsignedFloat('serving_weight'); diff --git a/database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php b/database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php new file mode 100644 index 0000000..131a28f --- /dev/null +++ b/database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php @@ -0,0 +1,33 @@ +string('source')->nullable()->after('brand'); + $table->string('notes')->nullable()->after('brand'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('foods', function (Blueprint $table) { + $table->dropColumn(['source', 'notes']); + }); + } +} diff --git a/resources/views/foods/edit.blade.php b/resources/views/foods/edit.blade.php index ed3d39f..90d86ee 100644 --- a/resources/views/foods/edit.blade.php +++ b/resources/views/foods/edit.blade.php @@ -115,6 +115,24 @@ + +
+ + + +
+ + +
+ + + +