mardi 20 août 2019

How to pass correct data from a dynamic button in Laravel 5.8

I have a dynamic buttons where it produced from my database

enter image description here

My code for that in blade file

<div class="input-group col-sm-12">
      <!--start of the form-->
       <form class="form-horizontal" method="POST" action="">

            

           <!--input type hidden department code below -->

           @foreach($departments as $department)
           <input type="hidden" id="dept_name" name="dept_name" value="">

           <input type="hidden" id="called" name="called" value="NO">

           <!--buttons -->    
           <button type="submit" class="btn btn-success btn-fill pull-right" id="form-button-add">
           
           </button>
           @endforeach
        </form>
        <!--end-->   
 </div>

Whenever I click either one, they'all add a data in my call database based on the values per button. My problem is when I click the cashier button, the values that would add would be the assessments.

My code in CallController

public function store(Request $request)
{
    $dept_id = Department::select('id')
        ->where('dept_name', $request->input('dept_name'))
        ->first();

    $let = Department::select('letter')
        ->where('dept_name', $request->input('dept_name'))
        ->first();
    $number = Department::select('start')
        ->where('id', $dept_id->id)         
        ->first();

    $call = Call::create([
        'dept_id' => $dept_id->id,
        'letter' => $let->letter,
        'number' => $number->start,
        'called' => $request->input('called')
    ]);

    Department::where('id', $dept_id->id)
    ->increment('start');

    return redirect()->route('call.index')->with('success' , 'NEW CALL');
}

I also dd each query and found out that the values would get are the values from assessment or the last value from the foreach loop in my blade file. How could I get the value of cashier when I click the cashier button instead of assessment.

I would show my database so that you understand my question

Department Table: id, dept_name, letter, start(int, it'll increment after producing a call)

Counter: id, counter_num, dept_id

Call Table: id, dept_id, letter, number, counter_id, called



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/30fhTie
via IFTTT

Aucun commentaire:

Enregistrer un commentaire