Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 [HELP] Checkbox in Laravel 5.4

views
     
TSMaster Oogway
post Mar 28 2017, 02:19 PM, updated 8y ago

Getting Started
**
Junior Member
68 posts

Joined: Mar 2016


i tried searching all over the tutorials but none of them giving me a hint

i have no ideas how to make checkboxes in my view blade

i would like to have a simple checkbox where it can access to the database dynamically

what should i put in controller, route and views?

Attached Image
iloveteddybear
post Mar 28 2017, 04:09 PM

Getting Started
**
Junior Member
216 posts

Joined: Jan 2010
QUOTE(Master Oogway @ Mar 28 2017, 03:19 PM)
i tried searching all over the tutorials but none of them giving me a hint

i have no ideas how to make checkboxes in my view blade

i would like to have a simple checkbox where it can access to the database dynamically

what should i put in controller, route and views?

Attached Image
*
What do you mean by checkbox access database dynamically?

Do you mean loading the checkbox value through query?

If you are populating the checkbox (either checked or unchecked), for example if your database holds value 1 for checkbox A, just load it in to your view.

1) Pass the query from your controller to view
2) Check value from view and populate your checkbox with the value

Done smile.gif
Yolo Swag
post Mar 28 2017, 04:18 PM

New Member
*
Junior Member
15 posts

Joined: May 2015
QUOTE(iloveteddybear @ Mar 28 2017, 04:09 PM)
What do you mean by checkbox access database dynamically?

Do you mean loading the checkbox value through query?

If you are populating the checkbox (either checked or unchecked), for example if your database holds value 1 for checkbox A, just load it in to your view.

1) Pass the query from your controller to view
2) Check value from view and populate your checkbox with the value

Done smile.gif
*
php?

This post has been edited by Yolo Swag: Mar 28 2017, 04:20 PM
iloveteddybear
post Mar 28 2017, 04:29 PM

Getting Started
**
Junior Member
216 posts

Joined: Jan 2010
QUOTE(Yolo Swag @ Mar 28 2017, 05:18 PM)
php?
*
Yeah he said Laravel 5.4
Yolo Swag
post Mar 28 2017, 04:33 PM

New Member
*
Junior Member
15 posts

Joined: May 2015
QUOTE(iloveteddybear @ Mar 28 2017, 04:29 PM)
Yeah he said Laravel 5.4
*
lol first time heard laravel, I thought it was some software
TSMaster Oogway
post Mar 28 2017, 04:45 PM

Getting Started
**
Junior Member
68 posts

Joined: Mar 2016


QUOTE(Yolo Swag @ Mar 28 2017, 04:18 PM)
php?
*
yes php, with some laravel eloquent sweat.gif
TSMaster Oogway
post Mar 28 2017, 04:46 PM

Getting Started
**
Junior Member
68 posts

Joined: Mar 2016


QUOTE(iloveteddybear @ Mar 28 2017, 04:09 PM)
What do you mean by checkbox access database dynamically?

Do you mean loading the checkbox value through query?

If you are populating the checkbox (either checked or unchecked), for example if your database holds value 1 for checkbox A, just load it in to your view.

1) Pass the query from your controller to view
2) Check value from view and populate your checkbox with the value

Done smile.gif
*
not quite understand about your explaination, but could you provide some codes so that i can test them and understand them?
iloveteddybear
post Mar 28 2017, 05:04 PM

Getting Started
**
Junior Member
216 posts

Joined: Jan 2010
QUOTE(Master Oogway @ Mar 28 2017, 05:46 PM)
not quite understand about your explaination, but could you provide some codes so that i can test them and understand them?
*
Can show me the code you done and we do some modifications and amendments from there? smile.gif
cubiclecarbonate
post Mar 28 2017, 05:16 PM

On my way
****
Junior Member
557 posts

Joined: Jul 2011


QUOTE(Master Oogway @ Mar 28 2017, 02:19 PM)
i tried searching all over the tutorials but none of them giving me a hint

i have no ideas how to make checkboxes in my view blade

i would like to have a simple checkbox where it can access to the database dynamically

what should i put in controller, route and views?

Attached Image
*
controller
- pass your item collection

view
- use @foreach to iterate the collection
- inside loop put this <input type="checkbox" value="{{ ITEM_VALUE }}">{{ ITEM_DESC }}

forgot to add

your route shouldn't be an issue as it will route your form

This post has been edited by cubiclecarbonate: Mar 28 2017, 05:17 PM
TSMaster Oogway
post Mar 28 2017, 05:16 PM

Getting Started
**
Junior Member
68 posts

Joined: Mar 2016


QUOTE(iloveteddybear @ Mar 28 2017, 05:04 PM)
Can show me the code you done and we do some modifications and amendments from there? smile.gif
*
how do i save it to database?

CODE
<div class="form-group">
                                       {{ Form::label('Check A : ')}}
                                       {{Form::checkbox('databasecolumn', 'Value A')}}
                                       {{ Form::label('Check B : ')}}
                                       {{Form::checkbox('databasecolumn', 'Value B')}}
                                       {{ Form::label('Check C : ')}}
                                       {{Form::checkbox('databasecolumn', 'Value C')}}

                                   </div>


Attached Image
TSMaster Oogway
post Mar 28 2017, 05:33 PM

Getting Started
**
Junior Member
68 posts

Joined: Mar 2016


QUOTE(cubiclecarbonate @ Mar 28 2017, 05:16 PM)
controller
- pass your item collection

view
- use @foreach to iterate the collection
- inside loop put this <input type="checkbox" value="{{ ITEM_VALUE }}">{{ ITEM_DESC }}

forgot to add

your route shouldn't be an issue as it will route your form
*
in views
CODE
@foreach ($role as $r)
                                   <div class="form-group">

                                   <input type="checkbox" value="{{$r->role_name}}" name="role">{{$r->role_name}}
                                   </div>
                                   @endforeach


in controller

CODE
$role = DB::table('role')->pluck('role_name', 'id');

       return view('crud.index', compact('test', 'states', 'role'))->with('data',$data);
   }


error

CODE
Trying to get property of non-object

iloveteddybear
post Mar 28 2017, 05:41 PM

Getting Started
**
Junior Member
216 posts

Joined: Jan 2010
QUOTE(Master Oogway @ Mar 28 2017, 06:33 PM)
in views
CODE
@foreach ($role as $r)
                                   <div class="form-group">

                                   <input type="checkbox" value="{{$r->role_name}}" name="role">{{$r->role_name}}
                                   </div>
                                   @endforeach


in controller

CODE
$role = DB::table('role')->pluck('role_name', 'id');

       return view('crud.index', compact('test', 'states', 'role'))->with('data',$data);
   }


error

CODE
Trying to get property of non-object

*
Try using $r['role_name'] in your foreach loop, because u are using pluck which returns an array.
TSMaster Oogway
post Mar 29 2017, 08:42 AM

Getting Started
**
Junior Member
68 posts

Joined: Mar 2016


QUOTE(iloveteddybear @ Mar 28 2017, 05:41 PM)
Try using $r['role_name'] in your foreach loop, because u are using pluck which returns an array.
*
CODE
@foreach ($role as $r)
                                   <div class="form-group">

                                   <input type="checkbox" value="{{$r[role_name]}}" name="role">{{$r[role_name]}}
                                   </div>
                                   @endforeach


error

CODE
Use of undefined constant role_name - assumed 'role_name'

cubiclecarbonate
post Mar 29 2017, 11:47 AM

On my way
****
Junior Member
557 posts

Joined: Jul 2011


QUOTE(Master Oogway @ Mar 28 2017, 05:33 PM)
CODE

$role = DB::table('role')->pluck('role_name', 'id');
return view('crud.index', compact('test', 'states', 'role'))->with('data',$data);

*
try return like this

CODE
return view('crud.index', ['role'=>$role]);


 

Change to:
| Lo-Fi Version
0.0139sec    0.64    6 queries    GZIP Disabled
Time is now: 29th March 2024 - 05:25 PM