2017-11-02 01:58
浏览 215


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', '', '=', 'hires.user_id')->select('','personal_infos.Name','personal_infos.deleted_at','hires.hire_status')->where('deleted_at',NULL)->whereNull('hires.hire_status')->get()->sortByDesc('created_at');
        return view('hire',$data);
    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');


   <table class="table table-bordered">
        <th><strong><big>Name: </big></strong></th>     
        <th><strong><big>Hire Action: </big></strong></th>  
        @foreach($data as $value)
      <th><a href="{{route('',['id'=>$value->id])}}">{{$value->Name}}</a></th>
      <form class="form-horizontal" method="post" action="{{ url('/hire_status/'.$value->id) }}">
        {{ csrf_field() }}
         <input type="hidden" name="user_id" value="{{$value->id}}">
        <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">

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulei8861 2017-11-02 02:49

    With Eloquent models and relations between them properly defined, you'll be able to fetch all objects of ** personal_info** class that do not have a related hire record with:

    $personalInfos = personal_info::whereDoesntHave('hires')->get();
    打赏 评论

相关推荐 更多相似问题