2014-03-28 201 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實例是否有任何項目,如果沒有,則顯示「無搜索結果」消息。