php - How to retrieve the id of the new entry i just created with laravel RessourceApiController?

I want to return the id of the new entry i just created in my ToDoList table.
ToDoListController.php
public function store(Request $request)
{
ToDoList::create([
'title' => $request->input('title'),
'state' => $request->input('state'),
'closed' => $request->input('closed'),
]);
return response()->json(["id" => $id?], 200);
}
ToDoList.php
class ToDoList extends Model
{
protected $fillable = ['title', 'state', 'closed' ];
}
Answer
Solution:
create variable withToDoList
model
public function store(Request $request)
{
$todo = ToDoList::create([
'title' => $request->input('title'),
'state' => $request->input('state'),
'closed' => $request->input('closed'),
]);
return response()->json(["id" => $todo->id], 200);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mark bundle as not supporting multiuse
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.