php - Laravel 4.2 不返回 View ::make

标签 php mysql laravel laravel-4 mariadb

好的,Laravel 4.2;玛丽亚数据库;等

尝试查询 SQL 字符串“test”,我知道自从创建它以来它就在那里。

这是我的 SearchController.php 代码:

 // Here search is ok.
        $start = microtime(true);
        $items = Project::processSearch('+' . implode(' +', $searchTerms), false, $this->limitPerPage, $page, $this->maxSearchResults);
        $executionTime = microtime(true) - $start;
        $total = $items->getTotal();

        if($total == 0)
        {
            $start = microtime(true);
            $items = Project::processSearch(implode(' ', $searchTerms),
                true, $this->limitPerPage, $page, $this->limitPerPage);
            $executionTime = microtime(true) - $start;

            $total = $items->getTotal();

            if($total > 0)
            {
                return View::make('search.results')
                    ->with('items', $items)
                    ->with('executionTime', number_format($executionTime, 4))
                    ->with('info', "Your query didn't return any result.");
            }
        }

这是我的类(class)代码

public static function processSearch($query, $suggestions, $resultsPerPage, $page, $limit = null)
{
    $slug = Str::slug($query) . '-general';
    $slug .= $suggestions ? '-suggestions' : '-exact-search';

    $results = Cache::remember($slug, 10, function() use($query, $limit)
    {
        $items = Project::whereRaw(
            "MATCH(mixed) AGAINST(? IN BOOLEAN MODE)",
            array($query)
        )->take(301);

        if(Auth::check())
        {
            $items = $items->with(['unlockedItemsUser' => function($query)
            {
                $query->where('user_id', '=', Auth::user()->id);
            }]);
        }

        if($limit != null)
        {
            $items = $items->limit($limit);
        }

        $items = $items->get();

        if(count($items) > 0 && is_object($items))
        {
            return $items->all();
        }

        return null;
    });

    if($results != null)
    {
        $pages = objectlist_chunk($results, $resultsPerPage);
        return Paginator::make($pages[$page - 1], count($results), $resultsPerPage);
    }

    return Paginator::make(array(), 0, $resultsPerPage);
}



public function unlockedItemsUser()
{
    return $this->hasMany('UnlockedItem', 'item_id', 'id');
}

public function newQuery($excludeDeleted = false)
{
    $query = parent::newQuery();
    if($excludeDeleted)
    {
        $query->where('deleted', '=', '0');
    }
    $query->where('blacklist', '=', 0);

    return $query;
}

}

这是我的路线

Route::controller('getIndex', 'SearchController');
Route::controller('/search', 'SearchController');
Route::resource('getIndex', 'SearchController');
Route::controller('/user', 'UserController');
Route::controller('/maintenance', 'MaintenanceController');

我在mysql中正确的表和数据库中创建了字符串“test”;一切安好。但是当我尝试查询“测试”时,它返回“未找到结果”;即使我清楚地看到它。

不知道这是否有帮助;但这里有一个我发现很有趣的分析器部分: enter image description here

提前谢谢您!

最佳答案

如果您第一次调用 processSearch 给您带来了值(value),您就不会返回任何 View 。

$start = microtime(true);
$items = Project::processSearch('+' . implode(' +', $searchTerms), false, $this->limitPerPage, $page, $this->maxSearchResults);
$executionTime = microtime(true) - $start;
$total = $items->getTotal();

if($total == 0)
{
    $start = microtime(true);
    $items = Project::processSearch(implode(' ', $searchTerms),
        true, $this->limitPerPage, $page, $this->limitPerPage);
    $executionTime = microtime(true) - $start;

    $total = $items->getTotal();

    if($total > 0)
    {
        return View::make('search.results')
            ->with('items', $items)
            ->with('executionTime', number_format($executionTime, 4))
            ->with('info', "Your query didn't return any result.");
    } else {

        return View::make('search.results')
            ->with('items', $items)
            ->with('executionTime', number_format($executionTime, 4))
            ->with('info', 'There is nothing to show');
    }
}

return View::make('search.results')
            ->with('items', $items)
            ->with('executionTime', number_format($executionTime, 4));

关于php - Laravel 4.2 不返回 View ::make,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43491546/

相关文章:

javascript - 我正在构建一个 Youtube 订阅下载门..并且我希望在单击订阅按钮后出现一个按钮

mysql - "Failed to establish a database connection. Check connection string, username and password."背后的根本错误是什么

php - 如何在 Laravel 中使用 AJAX 调用资源 Controller 的编辑方法?

php - Laravel 5.5 模型上的自定义软删除

PHP:区域设置感知数字格式

PHP - 如何在 POST 之前从查询填充的下拉菜单中获取所选项目

php - 使用表单上的 php/mysql 数据库查询和单选按钮进行实时刷新

mysql - mysql 中的 Not IN 运算符返回 NULL

MySQL 关于重复键...获取现有 ID?

php - Laravel 5 - 重定向到 HTTPS