sarga/packages/Webkul/Shop/src/Http/Controllers/SearchController.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2018-10-28 13:23:20 +00:00
<?php
namespace Webkul\Shop\Http\Controllers;
2019-07-01 11:33:36 +00:00
use Webkul\Product\Repositories\SearchRepository;
2018-10-29 06:09:09 +00:00
2018-10-28 13:23:20 +00:00
/**
* Search controller
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
2019-07-01 11:33:36 +00:00
class SearchController extends Controller
2018-10-28 13:23:20 +00:00
{
2019-07-01 11:33:36 +00:00
/**
* Contains route related configuration
*
* @var array
*/
2018-10-28 13:23:20 +00:00
protected $_config;
2019-07-01 11:33:36 +00:00
/**
* SearchRepository object
*
* @var Object
*/
protected $searchRepository;
2018-10-29 06:09:09 +00:00
2019-07-01 11:33:36 +00:00
/**
* Create a new controller instance.
*
* @param \Webkul\Product\Repositories\SearchRepository $searchRepository
* @return void
*/
public function __construct(SearchRepository $searchRepository)
2018-10-28 13:23:20 +00:00
{
$this->_config = request('_config');
2019-07-01 11:33:36 +00:00
$this->searchRepository = $searchRepository;
2018-10-28 13:23:20 +00:00
}
/**
* Index to handle the view loaded with the search results
*/
public function index()
{
2019-07-01 11:33:36 +00:00
$results = $this->searchRepository->search(request()->all());
2018-10-29 06:09:09 +00:00
2019-07-01 11:33:36 +00:00
return view($this->_config['view'])->with('results', $results->count() ? $results : null);
2018-10-28 13:23:20 +00:00
}
}