2015-01-31 10 views
33

के बराबर नहीं है, मैं नवीनतम लैरावेल इंस्टॉल का उपयोग कर रहा हूं।एलोक्वेंट - जहां

मेरे तालिका संरचना इस प्रकार है:

Code::where('to_be_used_by_user_id', '<>' , 2)->get() 
Code::whereNotIn('to_be_used_by_user_id', [2])->get() 
Code::where('to_be_used_by_user_id', 'NOT IN', 2)->get() 

आदर्श रूप में, यह पिछले 3 रिकॉर्ड लौटना चाहिए: https://www.uploady.com/#!/download/OQSH4ualzUD/x2SIqdcaulqzSSsy

मैं इन प्रश्नों की कोशिश की। लेकिन यह खाली सरणी देता है। मैं इससे कैसे निपटूं? कृपया मदद करे।

Code::all() 

सभी 4 रिकॉर्ड लौटाता है।

कोड मॉडल:

<?php namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Code extends Model 
{ 

    protected $fillable = ['value', 'registration_id', 'generated_for_user_id', 'to_be_used_by_user_id', 'code_type_id', 'is_used']; 

    public function code_type() 
    { 
     return $this->belongsTo('App\CodeType'); 
    } 

} 
+4

downvote की व्याख्या करें। मैं सवाल को सुधार दूंगा। – aBhijit

उत्तर

82

उपयोग where संयोजन में एक != ऑपरेटर के साथ whereNull

Code::where('to_be_used_by_user_id', '!=' , 2)->orWhereNull('to_be_used_by_user_id')->get() 
+0

हम्म यह वास्तव में काम करना चाहिए। मुझे लगता है कि त्रुटि कहीं और है। क्या आप अपना प्रश्न अपने कुछ कोड के साथ अपडेट कर सकते हैं? – lukasgeiter

+1

यह कुल रिकॉर्ड अनदेखा कर रहा है। यदि मैं एनयूएलएल में से किसी एक को गैर-नल आईडी में 2 से बदलता हूं, तो वह रिकॉर्ड वापस आ जाता है। 'इसे' से, मेरा मतलब है MySQL। – aBhijit

8

साथ where field not empty के लिए यह मेरे लिए काम किया:

->where('table_name.field_name', '<>', '') 
संबंधित मुद्दे