第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Laravel 中提交帖子 - 找不到兩分鐘的數(shù)字

在 Laravel 中提交帖子 - 找不到兩分鐘的數(shù)字

PHP
有只小跳蛙 2021-10-22 14:10:07
我正在嘗試提交一篇簡單的博客文章。我使用請求對象作為 DTO 傳遞數(shù)據(jù)。public function store(CreateBlogRequest $createBlogRequest){    $user = User::find(1);    $post = $user->posts()->create([$createBlogRequest]);}我收到以下錯誤:"message": "發(fā)現(xiàn)意外數(shù)據(jù)。\n發(fā)現(xiàn)意外數(shù)據(jù)。\n發(fā)現(xiàn)意外數(shù)據(jù)。\n找不到兩位數(shù)的分鐘\n找不到兩位數(shù)的秒\n尾隨數(shù)據(jù)"但是,當(dāng)我將數(shù)據(jù)作為標(biāo)準(zhǔn)數(shù)組傳遞時,它運行良好。public function store(Request $request){    $user = User::find(1);    $post = $user->posts()->create(['title' => $request->title, 'slug' => $request->slug, 'body' => $request->body]);}崗位模型class Post extends Model{    protected $guarded = [];    protected $dates = ['created_at','updated_at'];    protected $dateFormat = 'Y-m-d H:i:s';     public function user()    {        return $this->belongsTo('App\User');    }}知道這里有什么問題嗎?
查看完整描述

1 回答

?
慕尼黑8549860

TA貢獻1818條經(jīng)驗 獲得超11個贊

你不能只傳遞請求對象(你也把它包裝在一個數(shù)組中)。該create()方法需要一個關(guān)聯(lián)數(shù)組。

相反,您可以執(zhí)行在第二個示例中所做的操作?;蛘呦襁@樣:

$post = $user->posts()->create($createBlogRequest->input());

或更明確(更安全):

$post = $user->posts()->create($createBlogRequest->only(['title', 'slug', 'body']));

不過,您可能需要創(chuàng)建字段$fillable。


查看完整回答
反對 回復(fù) 2021-10-22
  • 1 回答
  • 0 關(guān)注
  • 148 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號