首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到类“输入”

未找到类“输入”
EN

Stack Overflow用户
提问于 2016-06-17 21:11:46
回答 2查看 3.5K关注 0票数 3

我正试图为我的Laravel5.2应用程序实现智能搜索引擎。这里是Laravel 4的教程,我想在Laravel 5中实现:

https://maxoffsky.com/code-blog/laravel-shop-tutorial-3-implementing-smart-search/

但是我被困在ApiSearchController里,我得到了:

代码语言:javascript
复制
Class 'Input' not found

这是我的控制器

代码语言:javascript
复制
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Input;
use App\Http\Requests;

class ApiSearchController extends Controller
{
    public function index()
    {
        $query = e(Input::get('q',''));

        if(!$query && $query == '') return Response::json(array(), 400);

        $products = Product::where('published', true)
            ->where('name','like','%'.$query.'%')
            ->orderBy('name','asc')
            ->take(5)
            ->get(array('slug','name','icon'))->toArray();

        $categories = Category::where('name','like','%'.$query.'%')
            ->has('products')
            ->take(5)
            ->get(array('slug', 'name'))
            ->toArray();

        // Data normalization
        $categories = $this->appendValue($categories, url('img/icons/category-icon.png'),'icon');

        $products   = $this->appendURL($products, 'products');
        $categories  = $this->appendURL($categories, 'categories');

        // Add type of data to each item of each set of results
        $products = $this->appendValue($products, 'product', 'class');
        $categories = $this->appendValue($categories, 'category', 'class');

        // Merge all data into one array
        $data = array_merge($products, $categories);

        return Response::json(array(
            'data'=>$data
        ));
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-17 21:15:19

是的,我找到了解决这个问题的方法,我使用并成功了。

代码语言:javascript
复制
in config.php
'Input' => Illuminate\Support\Facades\Input::class,

代码语言:javascript
复制
in Controller
use Input;
票数 1
EN

Stack Overflow用户

发布于 2016-08-02 11:40:43

您需要在aliases中添加config/app.php添加行到aliases

代码语言:javascript
复制
'Input' => Illuminate\Support\Facades\Input::class,
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37890429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档