DoubleUp's avatar

Button Clickable after event Laravel

Hello guys, 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.

0 likes
4 replies
DoubleUp's avatar

@Rutherfordium I have an error

Call to a member function isNotEmpty() on string

Here is my code

<a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary" @disabled($pekerjaans->bahp->isNotEmpty())>Penilaian</a>
Rutherfordium's avatar
Level 7

@DoubleUp It just check whether it's true or not, if it is true then it will be disabled if not it will be enabled. So you need to figure out how do you know if there is no file upload. If i'm not wrong using null checker can do the thing you w ant, something like th is @disabled(is_null($pekerjaans->bahp)

You can also use the conditional

1 like
DoubleUp's avatar

@Rutherfordium Thank you for the reply... I use this:

 @if (is_null($pekerjaans->bahp))
                            <a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary disabled">Penilaian</a>
                            @else
                            <a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary">Penilaian</a>
                            @endif

Thanks for the information really helpful

Please or to participate in this conversation.