Laravel阻止自动boot()函数调用

时间:2015-06-02 12:54:38

标签: php laravel laravel-4

我遇到了Laravel 4.2的问题。请看下面的代码:

Model/User.php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    public static function boot() {
        parent::boot();
        static::creating(function($post) {
            $post->created_by = Auth::user()->id;
            $post->updated_by = Auth::user()->id;
        });

        static::updating(function($post) {
            $post->updated_by = Auth::user()->id;
        });
    }
}

控制器/ UserController.php

$user = new User;
$user->username= 'John';
$user->password = Hash::make('123456');
$user->save();

每当我创建或更新 boot()的用户时,都会自动调用该函数。有没有办法阻止自动调用此函数?

0 个答案:

没有答案