mercredi 1 novembre 2017

How to query for "where data does not exist" in Laravel?

I am trying to make a query which says something like if hire_status exist, do not print out those value instead only print out those with hire_status that doesn't have value yet. But I do not know how to do it. I did something like that for now, can someone help me? Is another kind of function to do it?

What I want to do is inside the view file, when the user has inserted his data into the database, their name should disappear inside the view file to avoid clicking the person name twice. But I do not know how to do that

Here is the code:

     public function getHire(){
        $data['data'] = DB::table('personal_infos')->join('hires', 'personal_infos.id', '=', 'hires.user_id')->select('personal_infos.id','personal_infos.Name','personal_infos.deleted_at','hires.hire_status')->where('deleted_at',NULL)->whereNull('hires.hire_status')->get()->sortByDesc('created_at');
       if(count($data)>0){
        return view('hire',$data);
    }else{
    return view('hire');
}

personal_info models:

class personal_info extends Eloquent
{
    use SoftDeletes;
    protected $fillable = array('Email', 'Name');
    protected $table = 'personal_infos';
    protected $primaryKey = 'id';
    protected $dates = ['deleted_at'];
public function hires() {
        return $this->hasOne('App\hire','user_id');
    }
}

hire model:

   protected $fillable = array('hire_status','user_id');

public function personal_infos() {
    return $this->belongsTo('App\personal_info', 'user_id', 'id');
}

hire.blade.php

   <table class="table table-bordered">
      <tr>
        <th><strong><big>Name: </big></strong></th>     
        <th><strong><big>Hire Action: </big></strong></th>  
      </tr>
      <td>
      <tr>
        @foreach($data as $value)
      <tr>    
      <th><a href=""></a></th>
    <th> 
      <form class="form-horizontal" method="post" action="">
        
         <input type="hidden" name="user_id" value="">
        <input type="radio" name="hire_status" value="Yes"> Yes<br>
        <input type="radio" name="hire_status" value="No"> No<br> 

         <div class="form-group">
            <div class="col-md-6-offset-2">
              <input type="submit" class="btn btn-primary" value="Save">
            </div>
          </div>

        </form>  
   </th>             
      </tr>
        @endforeach
      </tr>
      </tr>
    </table>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2A8MBgb
via IFTTT

Aucun commentaire:

Enregistrer un commentaire