【发布时间】:2019-06-30 07:07:53
【问题描述】:
SQLSTATE[42S22]: 未找到列: 1054 未知列 'create_at' in 'order Clause' (SQL: select * from posts where posts.user_id = 2 and posts.user_id is not null order by create_at desc) (查看: D:\xampp\htdocs\xampp\praactise\freecode\resources\views\profiles\index.blade.php)
我试过了:php artisan migrate:fresh
index.blade.php
<div class="col-9 pt-5">
<div class=" d-flex justify-content-between align-items-baseline font-weight-bold"><h1>{{ $user->username }}</h1>
<a href="/p/create">Add New Post</a>
</div>
<div class="d-flex">
<div ><strong>{{ $user->posts->count() }}</strong> posts</div>
<div class="pl-5"><strong>23k</strong> followers</div>
<div class="pl-5"><strong>435</strong> following</div>
</div>
<div class="pt-4 font-weight-bold" ><strong>{{ $user->profile->title }}</strong></div>
<div>{{ $user->profile->description }}</div>
<div><a href="#">{{ $user->profile->url ??'N/A' }}</a></div>
</div>
</div>
<div class="row pt-5">
@foreach($user->$posts as $post)
<div class="col-4" >
<img src="/storage/{{ $post->image }}" class="w-100">
</div>
@endforeach
User.php 文件----
public function posts()
{
return $this->hasMany(Post::class)->orderBy('create_at','desc');
}
public function profile()
{
return $this->hasOne(Profile::class);
}
post.php 文件
class Post extends Model
{
protected $guarded=[];
public function user()
{
return $this->belongsTo(User::class);
}
}
【问题讨论】: