mirror of https://github.com/kcal-app/kcal.git
Add Goal factory
This commit is contained in:
parent
8fe730bb14
commit
a6c978981d
|
@ -75,7 +75,7 @@ class GoalController extends Controller
|
||||||
$attributes = $request->validate([
|
$attributes = $request->validate([
|
||||||
'from' => ['nullable', 'date'],
|
'from' => ['nullable', 'date'],
|
||||||
'to' => ['nullable', 'date'],
|
'to' => ['nullable', 'date'],
|
||||||
'frequency' => ['nullable', 'string'],
|
'frequency' => ['required', 'string'],
|
||||||
'name' => ['required', 'string'],
|
'name' => ['required', 'string'],
|
||||||
'goal' => ['required', 'numeric'],
|
'goal' => ['required', 'numeric'],
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Support\Nutrients;
|
use App\Support\Nutrients;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
@ -33,9 +34,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUpdatedAt($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUserId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUserId($value)
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
|
* @method static \Database\Factories\GoalFactory factory(...$parameters)
|
||||||
*/
|
*/
|
||||||
final class Goal extends Model
|
final class Goal extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supported options for thr frequency attribute.
|
* Supported options for thr frequency attribute.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Goal;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class GoalFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = Goal::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$from = $this->faker->dateTimeThisMonth;
|
||||||
|
$to = $this->faker->dateTimeBetween($from, '+1 year');
|
||||||
|
return [
|
||||||
|
'from' => $this->faker->randomElement([$from, null]),
|
||||||
|
'to' => $this->faker->randomElement([$to, null]),
|
||||||
|
'frequency' => $this->faker->randomElement(Goal::$frequencyOptions)['value'],
|
||||||
|
'name' => $this->faker->randomElement(Goal::getNameOptions())['value'],
|
||||||
|
'goal' => $this->faker->numberBetween(0, 2000),
|
||||||
|
'user' => $user,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue