我正在尝试对所有评论运行搜索查询。我遇到了许多问题。我将有两个搜索查询,一个在注释ID上运行搜索,另一个在用户名上运行搜索,该用户名通过用户\id fk连接到注释。
当前我遇到问题:
Too few arguments to function Illuminate\Support\Collection::get(), 0 passed in
桌子:
注释-ID、注释、用户ID、时间戳
用户-ID、名称、用户名
模型:
class Comment extends Model
{
public function author()
{
return $this->belongsTo('App\User','user_id');
}
}
控制器:
public function index(Request $request)
{
$comment =Comment::paginate(10);
$id=$request->input('id');
$name=$request->input('username');
if(!empty($id)){
$comment->where('id', $request->input('id') )->get();
}
if(!empty($name)){
$comment->where($comment->author->username, 'LIKE', '%'.$name.'%')->get();
}
return view('comments.index')->withComment($comment);
}
视图:
<div class="panel-body">
{!! Form::open(['route' => 'comments.index', 'method' => 'GET']) !!}
<div class="col-md-5">
{!! Form::label('id', 'Search By ID:') !!}
{!! Form::text('id', null, array('class' => 'form-control')) !!}
</div>
<div class="col-md-5">
{!! Form::label('username', 'Search By Username:') !!}
{!! Form::text('username', null, array('class' => 'form-control')) !!}
</div>
<div class="col-md-2">
{!! Form::submit('Find Comments', array('class' => 'btn btn-send ')) !!}
</div>
{!!Form::close()!!}
</div>
@foreach($comment as $comments)
//data
@endforeach