gpt4 book ai didi

php - 找不到 laravel 列 : 1054 Unknown column 'created_at' in 'order clause'

转载 作者:行者123 更新时间:2023-11-29 01:19:41 30 4
gpt4 key购买 nike

我已定义不使用时间戳,但 laravel 仍然强制使用时间戳...我使用的是 laravel 5.6。

例如,当我访问页面时 - http://mypage/api/videos/21/comments我收到一个错误 - “SQLSTATE[42S22]:未找到列:1054 ‘order 子句’中的未知列‘created_at’(SQL:从 videos_comments 中选择 *,其中 videos_commentsvideo_id = ▶"

app/Providers/VideoComment.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class VideoComment extends Model
{
protected $table = 'videos_comments';
public $timestamps = false;
protected $fillable = [
'text', 'userid', 'date'
];
public function videos() {
return $this->belongsTo('App\Video', 'id', 'video_id');
}
public function member() {
return $this->belongsTo('App\Member', 'userid', 'member_id');
}
}

app/Providers/Video.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;

class Video extends Model
{
protected $table = 'videos';
public $timestamps = false;
use Sluggable;

public function sluggable() {
return [
'slug' => [
'source' => 'title'
]
];
}
public function comments() {
return $this->hasMany('App\VideoComment', 'video_id', 'id');
}
public function member() {
return $this->belongsTo('App\Member', 'userid', 'member_id');
}
}

VideoCommentController.php 函数

   public function index(Video $video) {
return response()->json($video->comments()->with('member')->latest()->get());
}

最佳答案

如果您在查询中使用 latest(),那么您必须在数据库表中添加 created_at,read more.

关于php - 找不到 laravel 列 : 1054 Unknown column 'created_at' in 'order clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49594952/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com