0

This is my json array.

{"Project": [
 {
"name": "Project1",
"category": "Web",
"total_maintenance": "0",
"maintenance_start": "2021-11-01",
"maintenance_end": "2021-11-10",
"email": "test12323@test.com",
 },
{
"name": "Project1",
"category": "Mobile",
"total_maintenance": "0",
"maintenance_start": "2021-11-01",
"maintenance_end": "2021-11-10",
"email": "test12323@test.com",
},
]}

I want to be able to use 1 variable like Project[0]->name but i dont know how to. This is in my laravel function.

public function store(Request $request)
{
    // request()->validate([
    //     'name' => 'required',
    //     'category' => 'required',
    //     'total_maintenance' => 'required',
    //     'maintenance_start' => 'required',
    //     'maintenance_end' => 'required',
    //     'email'=> 'required',
    // ]);




    // \Log::info($request->getContent());

    $projects = $request->getContent();

    Log::info(var_dump(json_decode($request->getContent())->Project[0]->name));
}

I commented out the request()->validate because it keeps returning error saying the field is required if i use the json body above. That only worked for my postman is i use the params way. Anyway I tried Log::info(var_dump(json_decode($request->getContent())->Project[0]->name)); but i got the

Trying to get property 'Project' of non-object error.

I also tried $request->all() but another error too.

ander99
  • 9
  • 6

0 Answers0