2015-02-02 10 views
63

मैं सिर्फ Laravel के साथ शुरू कर दिया है और मैं इस त्रुटि मिलती है 'updated_at': Unknown column 'updated_at' insert into gebruikers (naam, wachtwoord, updated_at, created_at) मैं जानता हूँ कि इस updated_at बात टाइमस्टैम्प स्तंभ से होता है जब आप एक मेज की ओर पलायन, लेकिन मैं का उपयोग नहीं update_at। जब मैं लैरवेल ट्यूटोरियल का पालन करता था तब मैं इसका इस्तेमाल करता था लेकिन अब जब मैं अपनी खुद की चीजें बना रहा हूं (या बनाने का प्रयास कर रहा हूं) मुझे यह त्रुटि मिलती है, भले ही मैं टाइमस्टैम्प का उपयोग न करें। मुझे ऐसा स्थान नहीं मिल रहा है जहां इसका उपयोग किया जा रहा है। इस कोड है:Laravel: अज्ञात स्तंभ

नियंत्रक:

public function created() 
{ 
    if (! User::isValidRegister(Input::all())) 
    { 
     return Redirect::back()->withInput()->withErrors(User::$errors); 
    } 


     // Register the new user or whatever. 
     $user = new User; 
     $user->naam = Input::get('naam'); 
     $user->wachtwoord = Hash::make(Input::get('password')); 
     $user->save(); 

     return Redirect::to('/users'); 
} 

मार्ग:

Route::get('created', '[email protected]'); 

मॉडल:

public static $rules_register = [ 
    'naam' => 'unique:gebruikers,naam' 
]; 

public static $errors; 
protected $table = 'gebruikers'; 

public static function isValidRegister($data) 
    { 
     $validation = Validator::make($data, static::$rules_register); 

     if ($validation->passes()) 
     { 
      return true; 
     } 
     static::$errors = $validation->messages(); 
     return false; 
    } 

मैं कुछ भूल जाना चाहिए ... क्या कर रहा हूँ मैं यहाँ गलत कर रहा हूँ?

+0

यदि आपके पास कॉलम ** अपडेट_एट ** है तो अपनी तालिका जांचें! –

+0

@MehdiMaghrooni मैं नहीं। – Loko

+0

और यह समस्या है, आप उस स्तंभ तक पहुंचना चाहते हैं जो मौजूद नहीं है। आपको या तो अपनी तालिका को जोड़ने के लिए उसे बदलना होगा, या बस उसे हटा दें। – Yang

उत्तर

175

मॉडल में, नीचे दिए गए कोड को लिखें;

public $timestamps = false; 

यह काम करेगा।

+1

क्या आप कृपया थोड़ा सा वर्णन क्यों कर सकते हैं? –

9

जो लोग laravel 5 का उपयोग कर रहे हैं या इसके बाद के संस्करण सार्वजनिक संशोधक का उपयोग करना चाहिए अन्यथा यह एक अपवाद

फेंक होगा
Access level to App\yourModelName::$timestamps must be 
public (as in class Illuminate\Database\Eloquent\Model) 

public $timestamps = false; 
-3
$id = put her id; 
$update['user_id'] = $userId; 
Use where(array('_id'=>$id))->pull($update); 
0

एलेक्स और समीर, लेकिन क्यों आवश्यक है पर हो सकता है सिर्फ अतिरिक्त जानकारी से अच्छा जवाब डाल करने के लिए

public $timestamps = false; 

मुहर अच्छी तरह से सरकारी Laravel page पर समझाया गया है:

By default, Eloquent expects created_at and updated_at columns to exist on your >tables. If you do not wish to have these columns automatically managed by >Eloquent, set the $timestamps property on your model to false.

संबंधित मुद्दे