Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'Input' not found

I am trying to implement smart search engine for my Laravel 5.2 app. Here is the tutorial of Laravel 4 and I want to implement in Laravel 5:

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

but I am stuck in ApiSearchController and I am getting:

Class 'Input' not found

Here is my 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
        ));
    }
}
like image 483
Sid Heart Avatar asked Jun 30 '26 14:06

Sid Heart


2 Answers

Yes I Found Sollution This i use and success

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

and

in Controller
use Input;
like image 86
Sid Heart Avatar answered Jul 04 '26 20:07

Sid Heart


You need to add aliases in config/app.php add line to aliases

'Input' => Illuminate\Support\Facades\Input::class,
like image 36
Nikunj K. Avatar answered Jul 04 '26 20:07

Nikunj K.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!