mirror of https://github.com/kcal-app/kcal.git
Add Ingredient model
This commit is contained in:
parent
dbc7ad9c32
commit
18543c4971
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Ingredient;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IngredientController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Ingredient $ingredient
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Ingredient $ingredient)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Ingredient $ingredient
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Ingredient $ingredient)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Ingredient $ingredient
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Ingredient $ingredient)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Ingredient $ingredient
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Ingredient $ingredient)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Ingredient extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected array $fillable = [
|
||||
'name',
|
||||
'unit',
|
||||
'calories',
|
||||
'protein',
|
||||
'fat',
|
||||
'carbohydrates',
|
||||
];
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Ingredient;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class IngredientFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Ingredient::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateIngredientsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('ingredients', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('unit')->nullable();
|
||||
$table->unsignedFloat('calories')->default(0);
|
||||
$table->unsignedFloat('protein')->default(0);
|
||||
$table->unsignedFloat('fat')->default(0);
|
||||
$table->unsignedFloat('carbohydrates')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('ingredients');
|
||||
}
|
||||
}
|
|
@ -13,6 +13,6 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
// \App\Models\User::factory(10)->create();
|
||||
$this->call(IngredientSeeder::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Ingredient;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class IngredientSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$default_ingredients = [
|
||||
[
|
||||
'name' => 'black beans',
|
||||
'unit' => 'cup',
|
||||
'calories' => 236,
|
||||
'protein' => 15.9,
|
||||
'fat' => 0.972,
|
||||
'carbohydrates' => 42.3
|
||||
],
|
||||
[
|
||||
'name' => 'egg white',
|
||||
'calories' => 17.2,
|
||||
'protein' => 3.6,
|
||||
'fat' => 0.056,
|
||||
'carbohydrates' => 0.241
|
||||
],
|
||||
[
|
||||
'name' => 'milk, whole',
|
||||
'unit' => 'cup',
|
||||
'calories' => 146,
|
||||
'protein' => 8,
|
||||
'fat' => 7.81,
|
||||
'carbohydrates' => 11.4
|
||||
],
|
||||
[
|
||||
'name' => 'rice, brown (cooked)',
|
||||
'unit' => 'cup',
|
||||
'calories' => 238,
|
||||
'protein' => 5.32,
|
||||
'fat' => 1.87,
|
||||
'carbohydrates' => 49.6
|
||||
],
|
||||
];
|
||||
Ingredient::factory()->createMany($default_ingredients);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue