本期视频登录后即可观看

Laravel 9 小白入门

39 集视频
5小时5分钟
本期 Laravel 9 入门视频教程咱们使用最简单的方式实现博客更新逻辑
德雨 2023.01.01 10:56

编辑更新的时候报错这个  Call to a member function format() on string

我不太了解Coding10

国营 2023.01.01 11:48

视频里有相关说明,耐心看就好,不用那么着急,这就是积累的过程

Levy 2023.05.03 09:49

按照兄弟视频里的方法,还是会报 Call to a member function format() on string

laravel10版本。谢谢兄弟。

CODING10

CODING10

ahyol 2023.03.10 03:25

$post=Post::findOrfail($id);

        // 为了前端format方法时间显示

        $post->update([

            'published_at' => new DateTime($post->published_at)

        ]);

        return view('blogs.edit', compact('post'));


控制器 edit方法published_at在欻第页面之前 用new DateTime改一下就好了

Levy 2023.05.03 09:46

按照这个方法可以,

$post=Post::findOrfail($id);

        // 为了前端format方法时间显示

        $post->update([

            'published_at' => new \DateTime($post->published_at)   //在DateTime函数前面加了一个\ 可以,要不然会报找不到App\Http\Controllers\DateTime" not found

        ]);

        return view('blogs.edit', compact('post'));

国营 2023.05.04 15:37


class Post extends Model
{
    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'published_at' => 'datetime',
    ];
}

Laravel 10 中取消了过去的 $dates 属性转化方式,现在需要使用 $casts 完成属性映射转化。

微信扫码登录