How To Retrieve Radio Button Value In Laravel

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

We can retrieve radio button value in table using controller.

How To Retrieve Radio Button Value In Laravel

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

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

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


Step 2: Create a View file like blog.blade.php add table and row column for radio button.
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>Name</th>
            <th>Title</th>
            <th>Vehicle</th>
            <th>Gender</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>{{$product->gender}}</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'));   
    }


Step: 4 Make a route for connection with controller.
app/Http/routes.php

 

Route::get('blog', 'BlogController@index');

Related Post