Thanh Toàn
Thanh Toàn

Reputation: 145

Laravel get some values of checkbox

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.

Upvotes: 0

Views: 2106

Answers (2)

Troyer
Troyer

Reputation: 7013

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.

Upvotes: 1

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

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');
}

Upvotes: 0

Related Questions