noblemfd
3 months ago
330
4
Laravel

How to make button visible based on the table field value

Posted 3 months ago by noblemfd

I have this code in my Laravel-5.8

Controller

    public function manager_review(Request $request)
    {
     try {  

        if (Auth::user()->hasRole('Line Manager')) 
        {
            if($request->filled(['employee_id']))   //$request->input('employee_id')
            {
                $goalmanagers = AppraisalGoal::where('appraisal_identity_id', $identities->id)->where('is_mid_year_published', 1)->whereNull('deleted_at')
                    ->when($request->input('employee_id'), function ($query) use ($request) {
                    $query->where('employee_id', $request->input('employee_id'));
            })
            ->get();          

        $incompleteManagerCount = $goalmanagers->filter(function($item) {
               return ($item->line_manager_mid_year_approved == 1);
          })->count(); 

            }else
            {
                $goalmanagers = AppraisalGoal::where('appraisal_identity_id', $identities->id)->where('is_active', 0)->whereNull('deleted_at')->get();
            $incompleteManagerCount = $goalmanagers->filter(function($item) {
                   return ($item->line_manager_mid_year_approved == 1);
              })->count(); 

            }        

        }

        return view('year_setups.manager_review')
                    ->with(['goalmanagers' => $goalmanagers, 'incompleteManagerCount' => $incompleteManagerCount])
                    ->with('managerfilters', $managerfilters); 
        } catch (Exception $exception) {
            Session::flash('error', 'Action failed! Please try again');
            return back();
            }                     
    }

view

                 @foreach($goalmanagers as $key => $goalmanager)
                <tr>
                        <td>
                            {{$goalmanager->goaltype->name ?? '' }}
                        </td>                           

                </tr>
                @endforeach 
        
    <div class="row no-print">
            <div id="midyearResponse" class="col-lg-4">
        @if ($incompleteManagerCount)
	<button type="button"  class="btn btn-primary">Submit</button>
        @endif            
            </div>
            <div id="midyearRecall" class="col-lg-4">
               
                <button type="button" class="btn btn-success">Recall</button>
            </div>

    </div>  

line_manager_mid_year_approved is a field in appraisal_goals (AppraisalGoal)

From the code above, using

$incompleteManagerCount

I made

 <button type="button"  class="btn btn-primary">Submit</button>

visible only when line_manager_mid_year_approved == 1

and that is working perfectly.

Now, how do I make the second button

 <button type="button" class="btn btn-success">Recall</button>

to be visible only when

line_manager_mid_year_approved == 3

Thank you

Please sign in or create an account to participate in this conversation.