我已经为我的应用程序分配了搜索方法,并且我在两个表“ users”表和“ posts”表之间建立了关系,它们都具有相同的字段名称“ created_at”,并且当我想获取数据时,创建后,它将在用户表created_at字段中而不是在帖子表created_at字段中显示日期。我想要的只是如何告诉系统我要区分的表字段名称之间的区别。
ListingController.php
public function search(Request $request){
$posts = Post::with(['comments','category','creator'])
->join('users', 'posts.created_by', '=', 'users.id')
->where('slug', 'LIKE', '%'.$request->search. '%')
->orWhere('users.name', 'LIKE', '%'.$request->search. '%')
->where('status',1)->orderBy('posts.id','DESC')->paginate(5);
return view('front.listing',compact('posts'));
}
listing.blade.php
<div class="article_date">
by: <a href="{{ url('/author') }}/{{ $post->creator->id }}">{{ $post->creator->name }} </a> , {{$post->created_at->diffForHumans()}}
</div>