0

When i use get some values from checkbox by html:

<input type="checkbox" name="svdk_doiTuong[]" value="Mocoi"> Sinh viên mồ côi cả cha và mẹ<br/>
<input type="checkbox" name="svdk_doiTuong[]" value="Ngheo"> Sinh viên thuộc gia đình hộ nghèo (có sổ hộ nghèo)<br/>
<input type="checkbox" name="svdk_doiTuong[]" value="XuatSac"> Sinh viên có thành tích học tập xuất sắc học kỳ vừa rồi hoặc tân sinh viên là thủ khoa chuyên ngành.<br/>

And Laravel 5.x.x i use Request object:

public function MyMethod(Request $request)
{
    $cameraVideo = $request->input('svdk_doiTuong');
    ...
}

Then, it happens errors, That's "Array to string conversion". Give me any ideas get some values, thank you.

7
  • $request->get('svdk_doiTuong'); Commented Apr 11, 2018 at 9:53
  • in which line the error comes Commented Apr 11, 2018 at 9:55
  • $request->input('svdk_doiTuong'); will return an array of checked values, so handle that as an array Commented Apr 11, 2018 at 9:55
  • Looks like you are managing the requested input as string, you need to know it's an Array. Probably you are printing it with echo, use dd() instead. Commented Apr 11, 2018 at 9:56
  • 1
    from my testing the $request->input('svdk_doiTuong'); or $request->get('svdk_doiTuong'); or $request->svdk_doiTuong; doesn't have any differences. Like @Troyer said "the problem is you are managing the retrieved data as String" Commented Apr 11, 2018 at 10:18

2 Answers 2

1

Your code is correct, you can use $request->svdk_doiTuong; but there's no difference between $request->input('svdk_doiTuong').

The problem is you are managing the retrieved data as String, when its an Array, probably you are trying to print it doing an echo to the variable, you should use the Laravel helper dd() or var_dump() instead, and if its an Array will not throw any error.

You need to provide more code to see what's causing the error.

Sign up to request clarification or add additional context in comments.

5 Comments

thank you for your detail explanation. i coudn't solve in Request Objects because it test before going on to create " dd()" or " var_dump() " @@.
@ThanhToàn put a dd($cameraVideo); just after the $cameraVideo = $request->input('svdk_doiTuong'); statement and show us what you get.
When i choose all 3 checkbox; this shows such as: array:3 [▼ 0 => "Mocoi" 1 => "Ngheo" 2 => "Xuatsac" ]
Looks like i get it that i choose . What should i do to finish it?
@ThanhToàn It means the error not doesn't come from $cameraVideo = $request->input('svdk_doiTuong'); this line. You should show the rest of the code to see what line causes the problem.
0

You should try this:

public function MyMethod(Request $request)
{
   $cameraVideo = $request->svdk_doiTuong;
   ...
}

OR

use Illuminate\Support\Facades\Input;
public function MyMethod(Request $request)
{
   $cameraVideo = Input::get('svdk_doiTuong');
}

5 Comments

post your full Mymethod() function
Sorry. look like my laravel doesnt understand "Input " although i used "use Input".....Error is ''Class 'Input' not found''
is there any other codes in your function @ThanhToàn
@AddWebSolutionPvtLtd . Looks like your code coudn't solve with this proplem
@afsalc right! but i don't have any ideas convert from array to strings

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.