0

I'm trying to figure out how to properly structure request data into an array in my controller. I have 3 values coming from my http request and I'm trying to get two of them into a specific array structure. My request values are dumping so they are definitely there.

Here's my controller where I"m putting them into an array:

 $subItems = array("title" => $request->itemTitle, "description" => $request->itemDesc);

But it's failing because the function I'm calling with the array $subItems is expecting an array structure where it can get the paramaters by the index of title and description like this:

 [ $subtask['title'], $subtask['description']]

How do I need to change my controller/array code to accomplish this?

2
  • You can use like this $subItems['title'] = $request->itemTitle ; After you cant get values using its key. In your question you add values to $subItems but you getting values from $subtask . Please check that one also. Commented Sep 2, 2019 at 6:14
  • This is weird. What does var_dump($subItems) give you inside the function you are calling? Commented Sep 2, 2019 at 6:28

2 Answers 2

1

You can do it like below

$subItems = [];
$subItems['title'] = $request->itemTitle;
$subItems['description'] = $request->itemDesc;
Sign up to request clarification or add additional context in comments.

Comments

0

You can use like this,

$subItems['title'] = $request->itemTitle; 

After you cant get values using its key. In your question you add values to $subItems but you getting values from $subtask Please check that one also.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.