gpt4 book ai didi

search - 找不到类 'Input'

转载 作者:行者123 更新时间:2023-12-04 03:25:34 24 4
gpt4 key购买 nike

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

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

但我被困在 ApiSearchController 中并且我得到:

Class 'Input' not found

这是我的 Controller

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

最佳答案

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

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

in Controller
use Input;

关于search - 找不到类 'Input',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37890429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com