您好我已经在laravel中实现了一个搜索工具,它会返回搜索查询,但我也会在laravel日志中收到此错误,如下所示:
[2014-09-14 21:06:20] production.ERROR: exception
'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method
Illuminate\Database\Eloquent\Collection::links()' in
/media/sf_Sites/tempus/app/storage/views/424d7d6280a6a7c59b31268a6d17e44a:27
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
#1 {main} [] []
我的代码如下:
项目/索引
@extends('layouts.master')
@section("content")
<div class="container">
<div>
{{ Form::open(['method' => 'GET', 'class' => 'nav-bar-form navbar-right']) }}
<div class="form-group">
{{ Form::input('search', 'q', null,['class' => 'form-control','placeholder' => 'Search']) }}
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
@if (Auth::check())
@if (count($projects) > 0)
@foreach ($projects as $project)
<p> {{ $project->project_name }}</p>
@endforeach
@else
<h5 class="errorslist">No match found</a></h5>
@endif
@endif
</div>
<div class="container">
<ul class="pagination">
<li>{{ $projects->links() }}</li>
</ul>
</div>
{{ Form::close() }}
@stop
存储库
public function searchProjects($query){
return \Project::where('project_name', 'LIKE', "%$query%" )
->orderby('project_name', 'asc')
->get();
}
public function getAll()
{
// get all logged in users projects and paginate 9 per page
return \Auth::user()->projects()->orderBy('project_name', 'asc')->paginate(9);
}
控制器:
public function index()
{
$query = Request::get('q');
$projects = $query
? $this->project->searchProjects($query)
: $this->project->getAll();
echo View::make('projects.index', compact('projects'));
}
路线
Route::get('projects/index', array('before' => 'auth',
"as" => "projects/index",
"uses" => "ProjectController@index"
));
我不确定为什么在我的链接方法上执行搜索查询时出现错误,有什么想法吗?
答案 0 :(得分:1)
您的searchProjects方法也需要分页:
public function searchProjects($query){
return \Project::where('project_name', 'LIKE', "%$query%" )
->orderby('project_name', 'asc')
->paginate(9);
}