2014-03-28 200 views
0

我有以下问题?当您在我们的平台上搜索foo时,您会得到一个空白页面的搜索结果。如果用户在不在我们平台上的搜索查询中输入搜索结果,并显示一个像“很抱歉但我们的平台上没有foo”这样的小反应,我想要输入一个搜索结果。Laravel搜索结果

在我们searchcontroller.php下控制器我有以下

<?php 

class SearchController extends BaseController 
{ 
public function getIndex() 
{ 
    $search = Request::get('q'); 
    if (empty($search)) { 
     return Redirect::to('gallery'); 
    } 
    $extends = explode(' ', $search); 


    $images = Images::where('title', 'LIKE', '%' . $search . '%') 
     ->orWhere('tags', 'LIKE', '%' . $search . '%')->orWhere('category', '=', $search) 
     ->where('deleted_at', '=', NULL)->where('approved','=',DB::raw(1))->orderBy('created_at', 'desc'); 

    foreach ($extends as $extend) { 
     $images->orWhere('tags', 'LIKE', '%' . $extend . '%') 
      ->orWhere('title', 'LIKE', '%' . $search . '%') 
      ->orWhere('image_description', 'LIKE', '%' . $search . '%'); 
    } 
    $images = $images->paginate(30); 

    return View::make('gallery/index') 
     ->with('images', $images) 
     ->with('title', t('Searching for').' "' . ucfirst($search) . '"'); 

} 

}

+0

“我想...”然后做。具体是什么问题? – bjb568

回答

0

在你看来,你会做这样的事情:

@if ($images->isEmpty()) 
    Sorry but we found no search results. 
@else 
    @foreach ($images as $image) 
     <img src="{{ $image }}"> 
    @endforeach 
@endif 

这更多的伪代码,然后任何东西。基本上只是检查Paginator实例是否有任何项目,如果没有,则显示“无搜索结果”消息。