Php 未找到laravel列:1054 order子句中的未知列“created_at”
我已经定义了不使用时间戳,但拉威尔仍然强制使用时间戳。。。我使用的是Laravel5.6 例如,当我访问页面时- 我收到一个错误-SQLSTATE[42S22]:未找到列:在“order子句”中的1054未知列“created_at”SQL:select*from videos_comments,其中videos_comments.video_id=▶ app/Providers/VideoComment.phpPhp 未找到laravel列:1054 order子句中的未知列“created_at”,php,mysql,laravel,Php,Mysql,Laravel,我已经定义了不使用时间戳,但拉威尔仍然强制使用时间戳。。。我使用的是Laravel5.6 例如,当我访问页面时- 我收到一个错误-SQLSTATE[42S22]:未找到列:在“order子句”中的1054未知列“created_at”SQL:select*from videos_comments,其中videos_comments.video_id=▶ app/Providers/VideoComment.php <?php namespace App; use Illuminate\
<?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');
}
}
如果在查询中使用最新方法,则必须在db表中添加created_at,最新和最旧的方法允许您轻松地按日期排序结果。默认情况下,结果将按created_at列排序。您可以轻松地使用orderBy and first,而不是latest,如果您尚未创建_at列 从索引函数hello@LightScribe VideoCommentController.php文件中的查询中删除->最新,包括查询的最新删除。最新和最旧的方法允许您轻松按日期排序结果。默认情况下,结果将按创建的_at列排序。@Sohel0415 Mayur Panchal。谢谢你帮了我的忙。
<?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');
}
}
public function index(Video $video) {
return response()->json($video->comments()->with('member')->latest()->get());
}