Posted inTechnology / jQuery / Laravel

Laravel get multiple checkbox value From View to Controller

Today, We want to share with you Laravel get multiple checkbox value From View to Controller.In this post we will show you how to insert multiple checkbox value in database in laravel, hear for insert multiple checkbox value in database using laravel we will give you demo and example for implement.In this post, we will learn about how to save multiple checkbox value in database in laravel with an example.

Laravel get multiple checkbox value From View to Controller

There are the Following The simple About Laravel get multiple checkbox value From View to Controller Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to get multiple checkbox value from database in php Laravel, so the some major files and Directory structures for this example is following below.

  • Laravel get value from checkbox
  • get multiple checkbox value in laravel

Example 1 : get Checkedd Checkbox values From View to Controller

View Blade Files in Laravel

id}}"> 

Request object get in Controller

public function store(Request $request)
{
    $members_ids = $request->input('members_ids');
    dd($members_ids);
}

Example 2 : Laravel get value of checkbox

Laravel blade View Files

 I have a Jaydeep
  I have a Krunal
I have a Ankit

Laravel Models

class Member extends Model {

 protected $table = 'members';

    protected $fillable = ['team_name','status_id','member_address','members'];
}

Laravel controller

public function store(ProductRequest $request)
{
    // The Source code
    $memberString = implode(",", $request->get('members'));

    // $memberString should return a value of 'Jaydeep, Krunal, Ankit' check it out just in case.

    $status = $this->member->create([
        'teamname' => $request->get('team_name'),
        'status_id' => $request->get('status_id'),
        'member_address' => $request->get('member_address'),
        'members' => $memberString
    ]);

    if($status)
    {
        \Session::flash('flash_message','Members created!!');
    } else {
        \Session::flash('flash_message','Error!');
    }

    return redirect('admin/members');
}

Get Multiple Values of Selected Checkboxes in Laravel

To get the multiple values of selected checkboxes in Laravel, you can use the Request object that is available in your controller method after submitting the form. Here’s an example:

In your HTML form, you need to add the name attribute to your checkboxes so that you can access the values in your controller method. For example:

@csrf Red
Green
Blue

In this example, we’re using the [] syntax in the name attribute to indicate that the form input is an array. When the form is submitted, the selected checkboxes will be sent to the server as an array of values.

In your controller method, you can use the Request object to access the values of the selected checkboxes. For example:

public function processForm(Request $request)
{
    $colors = $request->input('colors');
    // $colors is now an array containing the selected checkbox values
}

In this example, we’re using the input() method of the Request object to get the value of the colors field, which is an array of selected checkbox values. You can then use the $colors variable to perform any necessary processing, such as saving the selected values to a database or displaying them in a view.

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel get multiple checkbox value From View to Controller.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype