How To Retrieve Check Box Value In Laravel

admin_img Posted By Bajarangi soft , Posted On 20-01-2021

We can retrieve check box value in table using controller.

How To Retrieve Check Box Value In Laravel

Step 1:Create a table and model for fetching checkbox value.

class Blog extends Model
{
    public $table = 'product';

    protected $fillable = [
        'product_name', 'product_title','vehicle'
    ];
}


Step 2: Create a View file like blog.blade.php add some fields like Vehicle checkbox.
resources/views/welcome.blade.php

 

<html>
  <head>
   <title>Laravel </title>  
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> 
  </head>
<body><br>
<div id="alert" class="alert-success new-window" data-message="my message">
        </div>
<div class="container">
<div class="panel panel-primary">
 <div class="panel-heading">Products
 <button id="btn_add" name="btn_add" class="btn btn-default pull-right">Add New Product</button>
    </div>
      <div class="panel-body"> 
       <table class="table">
        <thead>
          <tr>
            <th>ID</th>
            <th>Product Name</th>
            <th>Product Title</th>
            <th>Vehicle</th>
            <th>Actions</th>
          </tr>   
         </thead>
         <tbody id="products-list" name="products-list">
           @foreach ($product as $product)
            <tr id="product">
             <td>{{$product->id}}</td>
             <td>{{$product->product_name}}</td>
             <td>{{$product->product_title}}</td>
             <td>
              <?php 
                $os = array($product->vehicle);
                $arrays = implode(' ', $os);              
                echo $arrays; 
              ?>
              </td>
              <td>
              <button class="btn btn-warning btn-detail open_modal btn-edit" value="{{$product->id}}">Edit</button>
              <button class="btn btn-danger btn-delete delete-product" value="{{$product->id}}">Delete</button>
              </td>
            </tr>
             @endforeach
        </tbody>
        </table>
       </div>
      </div>
</body>
</html>


Step: 3 Create a function in controller for get data from the database via model.
app/Http/Controllers/BlogController.php

 

public function index()
    {        
        $product = Blog::get();
        return view('blog',compact('product'));   
    }



 

Related Post