Add source and notes fields to foods

This commit is contained in:
Christopher C. Wells 2021-01-27 05:51:38 -08:00
parent ca55a0d6ec
commit 6baf888d4f
6 changed files with 63 additions and 0 deletions

View File

@ -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',

View File

@ -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,

View File

@ -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',

View File

@ -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');

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddSourceAndNotesToFoods extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('foods', function (Blueprint $table) {
$table->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']);
});
}
}

View File

@ -115,6 +115,24 @@
<!-- Tags -->
<x-tagger :defaultTags="$food->tags->pluck('name')"/>
<!-- Source -->
<div class="flex-auto">
<x-inputs.label for="source" value="Source" />
<x-inputs.input name="source"
type="text"
class="block mt-1 w-full"
:value="old('source', $food->source)" />
</div>
<!-- Notes -->
<div>
<x-inputs.label for="description" value="Description" />
<x-inputs.textarea name="notes"
class="block mt-1 w-full"
:value="old('notes', $food->notes)" />
</div>
</div>
<div class="flex items-center justify-end mt-4">