德雨 2023.01.01 10:56 编辑更新的时候报错这个 Call to a member function format() on string 我不太了解 回复 Codinget 2023.01.01 11:48 视频里有相关说明,耐心看就好,不用那么着急,这就是积累的过程 回复 Levy 2023.05.03 09:49 按照兄弟视频里的方法,还是会报 Call to a member function format() on string laravel10版本。谢谢兄弟。 回复 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')); 回复
Codinget 2023.01.01 11:48 视频里有相关说明,耐心看就好,不用那么着急,这就是积累的过程 回复 Levy 2023.05.03 09:49 按照兄弟视频里的方法,还是会报 Call to a member function format() on string laravel10版本。谢谢兄弟。 回复
Levy 2023.05.03 09:49 按照兄弟视频里的方法,还是会报 Call to a member function format() on string laravel10版本。谢谢兄弟。 回复
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')); 回复
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')); 回复
Codinget 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 完成属性映射转化。 回复
编辑更新的时候报错这个 Call to a member function format() on string
我不太了解
视频里有相关说明,耐心看就好,不用那么着急,这就是积累的过程
按照兄弟视频里的方法,还是会报 Call to a member function format() on string
laravel10版本。谢谢兄弟。
$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改一下就好了
按照这个方法可以,
$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'));
Laravel 10 中取消了过去的 $dates 属性转化方式,现在需要使用 $casts 完成属性映射转化。