课程'输入'找不到

时间:2016-06-17 21:11:47

标签: search laravel-5.2 search-engine

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

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

但我被困在ApiSearchController中,我得到了:

Class 'Input' not found

这是我的控制器

<?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
        ));
    }
}

2 个答案:

答案 0 :(得分:0)

是的,我找到了溶剂 我使用和成功

in config.php
'Input' => Illuminate\Support\Facades\Input::class,

in Controller
use Input;

答案 1 :(得分:0)

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

中添加aliases
'Input' => Illuminate\Support\Facades\Input::class,
相关问题