samedi 8 mai 2021

how to insert input text value on checkbox checked in laravel

may be this is common question. but i am new on laravel. I want to insert multiple input value in the table if checkbox checked.data is inserted on button click but the data is not inserted as checkbox checked.so i want to insert input type 'text' value should be insert as checkbox checked in sequential manner.. thank you in advance.

[this is model][1]
class chekbox extends Model
{
    protected $fillable = [
            'services',
            'mainFile_given_date',
            'mainFile_receiv_date',
            'investigator_id',
            'file_no',
            'theft_id',
            'status',
    ];
}
[this is blade image ][2]
<form action="" method="post">
            
            <table>
              @foreach($theft_File as $theft)
                <tr>
                  <td><input type="text" name="theft_id[]" value=""></td>
                <td><input type="text" name="file_no[]" value=""></td>
                <td><input type="checkbox" name="services[]" value=""/></td>
                </tr>
              @endforeach
            </table>
            <br>
          <button type="submit"> save </button>
        </form> 
[this is controller image...][3]
public function checkboxStore(Request $request){

        $services = $request->input('services');
        $theft_id = $request->input('theft_id');
        $file_no = $request->input('file_no');

        for($i=0; $i<count($services); $i++){
            $input['services']  = $services[$i];
            $input['theft_id'] = $theft_id[$i];
            $input['file_no'] = $file_no[$i];   
            $insertData = chekbox::create($input);   
        }
        session()->flash('success','Files assigned Successfully.');
        return redirect()->back();  
    }
  [1]: https://i.stack.imgur.com/Gem4P.png
  [2]: https://i.stack.imgur.com/xyHX9.png
  [3]: https://i.stack.imgur.com/1Jrv2.png



Aucun commentaire:

Enregistrer un commentaire