Skip to content
Advertisement

Laravel On click Event Button [Enable button after upload file]

I have a table which contain two buttons, one is for uploading a file and the other one is for giving score. What I want to do is to give a condition for the second button which is the scoring button, whereby it can’t be clicked (disabled) if there is no file uploaded. How can I achieve this?

Here is what my table looks like:

enter image description here

And here is my AdminController for the table

public function showpekerjaanppk(){
        if(Auth::user()->status=='super'){
            $pekerjaan = Pekerjaan::with('penyedia','user')->paginate();
            return view('admin.showpekerjaan', compact('pekerjaan'));
        }else{
            $pekerjaan = Auth::user()->pekerjaans;
            return view('admin.showpekerjaan', compact('pekerjaan'));
        }
        //return view('admin.showpekerjaan', compact('penyedia','pekerjaan','totalAvg'));
    }

And here is my blade file for the table

<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
              <div class="card">
                <div class="card-header">
                  @if (Auth::user()->status=='super')
                  <h3 class="card-title"><b>{{$penyedia->nama}}</b></h3> <br>
               
                  <h3 class="card-title">Nilai Total: <b>{{$totalAvg}}</b></h3> 
                  @else
                  <h3 class="card-title"><b></b></h3> <br>
               
                    <h3 class="card-title"></b></h3>
                  @endif
                <!-- /.card-header -->
                <div class="card-body table-responsive">
                  <table id="tabelpekerjaan" class="table table-bordered">
                    <thead>
                      <tr>
                        <th style="width: 10px" rowspan="2">No.</th>
                        <th rowspan="2">Tanggal</th>
                        <th rowspan="2">Paket Pekerjaan</th>
                        <th rowspan="2">Nama Perusahaan</th>
                        <th rowspan="2">Lokasi Pekerjaan</th>
                        <th rowspan="2">PPK</th>
                        <th rowspan="2">Nilai Kontrak</th>
                        <th rowspan="2">Nilai</th>
                        <th rowspan="2">BAHP</th>
                        <th colspan="2">Aksi</th>
                      </tr>

                      <tr>
                        <td>BAHP</td>
                        <td>Nilai</td>
                      </tr>
                    </thead>
                    <tbody>
                      @php $no = 1; /*$totalNilai = 0.0;*/ @endphp
                      @foreach ($pekerjaan as $pekerjaans)
                      <tr>
                        <td>{{$no++}}</td>
                        <td>{{$pekerjaans->tanggal}}</td>
                        <td>{{$pekerjaans->pekerjaan}}</td>
                        <td>{{$pekerjaans->penyedia->nama}}</td>
                        <td>{{$pekerjaans->lokasi}}</td>
                        <td>{{$pekerjaans->user->name}}</td>
                        <td>Rp. {{number_format($pekerjaans->nilai_kontrak,0,',',',')}}</td>
                        @php
                        $pekerjaans->nilai_total = $pekerjaans->nilai_1 + $pekerjaans->nilai_2 + $pekerjaans->nilai_3 + $pekerjaans->nilai_4;
                        @endphp
                        <td>{{$pekerjaans->nilai_total}}</td>
                        <td>{{$pekerjaans->bahp}}</td>
                        <td>
                          <a href="/bahp/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary">Upload</a>
                        </td>
                        <td>
                            <a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary">Penilaian</a> //disabled untill file uploaded
                        </td>
                      </tr>
                      @endforeach
                    </tbody>
                  </table>
                </div>
                <!-- /.card-body -->
              </div>
              <!-- /.card -->
              @if (Auth::user()->status=='super')
              <div class="card-footer">
                
                <a href="/datanilai_penyedia" type="button" class="btn btn-outline-secondary">Kembali</a>
                
              </div>
              @endif
            
    </div>
</section>

Thank you in advance.

Advertisement

Answer

@if(isset($pekerjaans->yourFileCulmnName))
<td>
    <a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary">Penilaian</a> //disabled untill file uploaded
</td>
@endif
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement