找不到“输入”类

问题描述 投票:0回答:2

我正在尝试为我的 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
        ));
    }
}
php laravel-5 search search-engine
2个回答
1
投票

是的,我找到了解决方案 我用这个并且成功了

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

in Controller
use Input;

1
投票

您需要在

aliases
中添加
config/app.php
将行添加到
aliases

'Input' => Illuminate\Support\Facades\Input::class,
© www.soinside.com 2019 - 2024. All rights reserved.