久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel 5.4 字段沒有默認值

Laravel 5.4 field doesn#39;t have a default value(Laravel 5.4 字段沒有默認值)
本文介紹了Laravel 5.4 字段沒有默認值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我遇到了這個錯誤,我檢查過的谷歌搜索結果都與我的問題不相似.

I am having this error and none of the googled result i checked is similar to my problem.

我有一個包含 Deal、User 和 Matches 類的應用程序

I have an application with class Deal, User, and Matches

一筆交易有很多匹配項.一個用戶有很多匹配.一個用戶有很多交易.

A deal has many matches. A user has many matches. A user has many deals.

我正在嘗試使用我的 Deal 對象創建一個新的匹配

I am attempting to create a new Match using my Deal object

$deal->matches()->create(['user_id'=>$id]);

這是我的匹配類,我已經定義了所有需要的關系

This is my match class, i have defined all needed relationships

class Match extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = [];
    public $timestamps = false;
    public $expired_on = "";


    public static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            $model->matched_on = $model->freshTimestamp();
        });
    }

    public function __construct(){
        $d = (new DateTime($this->matched_on))->modify('+1 day');
        $this->expired_on = $d->format('Y-m-d H:i:s');
    }


    /**
     * Get the user that owns the match.
     */
    public function user()
    {
        return $this->belongsTo('AppUser');
    }

    /**
     * Get the deal that owns the match.
     */
    public function deal()
    {
        return $this->belongsTo('AppDeal');
    }
}

當我嘗試創建新匹配項時,我不斷收到此錯誤.

And i keep getting this error when i attempt to create a new match.

Connection.php 第 647 行中的 QueryException:SQLSTATE[HY000]:一般錯誤:1364 字段user_id"沒有默認值(SQL:插入matches(deal_id)值(1))

QueryException in Connection.php line 647: SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into matches (deal_id) values (1))

我的守衛是一個空數組,可能是什么問題?

I have my guarded to be an empty array, what could be the problem?

推薦答案

移除 guarded 數組并添加 fillable 代替:

Remove the guarded array and add the fillable instead:

protected $fillable = ['user_id', 'deal_id'];

這篇關于Laravel 5.4 字段沒有默認值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: cao在线| 久久手机在线视频 | 成人免费在线 | 国产天天操 | 一区二区三区视频免费观看 | 男女啪啪网址 | 在线观看第一区 | 在线国产一区二区三区 | 在线观看www | 成年无码av片在线 | 精品视频一区二区三区四区 | 久久国产成人 | 国产一区高清 | 免费在线h视频 | 亚洲欧美在线观看 | 91久久精品国产91久久性色tv | 午夜成人免费视频 | 欧美一级在线观看 | 国产精品九九九 | 中文字幕亚洲精品 | 欧美黑人激情 | 免费观看羞羞视频网站 | 中文字幕av一区二区三区 | 成人在线视频观看 | 色综合久 | 狠狠骚| 中文字幕综合 | 色综合久久久久 | 日本精品网站 | 中文字幕乱码一区二区三区 | 偷拍亚洲色图 | 在线免费观看黄视频 | 91黄色免费看 | 亚洲女人天堂成人av在线 | 激情自拍偷拍 | 久久国产精品色av免费观看 | 日本亚洲精品 | 久久久久国产一级毛片高清网站 | 性国产xxxx乳高跟 | 亚洲日韩中文字幕一区 | 操操操操操 |