Hey all,
I working on a side project where I'm starting with TDD and have a test data set like this
/** @test */
public function it_can_create_diet_plans() {
$user = factory(User::class)->create();
$data = [
'diet_plan' => [
'id' => 1,
'user_id' => $user->id,
'active' => true,
'title' => 'Kost program til Simon',
'description' => 'Kost program til Simon Jensen',
'diet_days' => [
'id' => 1,
'diet_id' => 1,
'weekday' => 'Mandag',
'diet_meals' => [
'id' => 1,
'diet_day_id' => 1,
'meal' => 'Morgenmad',
'diet_items' => [
'id' => 1,
'diet_meal_id' => 1,
'grams' => '20',
'protein' => '22',
'carb' => '400',
'fat' => '20',
],
],
],
],
];
$create_diet = $this->actingAs($user)->post(route('diet.store'), $data);
dd($create_diet);
}
and right now I have this on my controller
public function store(Request $request)
{
$request = $request->all();
$diet_plan = $request['diet_plan'];
$diet_days = $request['diet_plan']['diet_days'];
$diet_meals = $request['diet_plan']['diet_days']['diet_meals'];
$diet_items = $request['diet_plan']['diet_days']['diet_meals']['diet_items'];
}
I like that this way and i think there must be a better way to handle that.