0

ログインしようとしたときにユーザーアカウントがまだ有効かどうかを確認するために、データベースに有効期限を保存する必要があります。

これは私のユーザーモデルです:

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

    use Authenticatable, CanResetPassword;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    protected $dates = [
        'expiration_date'
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'first_name',
        'last_name',
        'email',
        'password',
        'expiration_date'
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token'
    ];

    /**
     * Questa funzione fa in modo di criptare in automatico la password quando si crea un utente
     *
     * @param $password
     *
     * @return string
     */
    public function setPAsswordAttribute( $password )
    {
        return $this->attributes['password'] = bcrypt( $password );
    }

    public function setExpirationDateAttribute( $expiration )
    {
        return $this->attributes['expiration_date'] = Carbon::createFromDate('Y-m-d', $expiration);
    }
}

私のフォームには、日付ピッカーを使用してタブをフォーマットに設定するテキスト入力がありdd/mm/yyyyます。
DBで送信を押すと、0000-00-00 00:00:00

何が問題ですか?

4

1 に答える 1

1

コードからわかるようCarbon::createFromDate($year = null, $month = null, $day = null, $tz = null)に、メソッドは 4 つのパラメーターを受け入れ、無効な引数を渡しています。

あなたが探しているメソッドはCarbon::createFromFormat($format, $time, $tz)、フォーマット、日付または時刻を含む文字列、および DateTimeZone インスタンスまたは文字列のタイムゾーンをパラメーターとして受け入れるものだと思います。

于 2015-02-08T10:50:04.477 に答える