55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Movie;
|
|
use App\Models\Person;
|
|
use App\Models\Show;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SearchController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$query = $request->input('query');
|
|
$type = $request->input('type', 'all');
|
|
|
|
$movies = collect([]);
|
|
$shows = collect([]);
|
|
$people = collect([]);
|
|
|
|
if ($query) {
|
|
// Search for movies if type is 'all' or 'movie'
|
|
if ($type === 'all' || $type === 'movie') {
|
|
$movies = Movie::where('title', 'like', "%{$query}%")
|
|
->orWhere('overview', 'like', "%{$query}%")
|
|
->limit(20)
|
|
->get();
|
|
}
|
|
|
|
// Search for TV shows if type is 'all' or 'tv'
|
|
if ($type === 'all' || $type === 'tv') {
|
|
$shows = Show::where('name', 'like', "%{$query}%")
|
|
->orWhere('overview', 'like', "%{$query}%")
|
|
->limit(20)
|
|
->get();
|
|
}
|
|
|
|
// Search for people if type is 'all' or 'person'
|
|
if ($type === 'all' || $type === 'person') {
|
|
$people = Person::where('name', 'like', "%{$query}%")
|
|
->limit(20)
|
|
->get();
|
|
}
|
|
}
|
|
|
|
return view('search.results', [
|
|
'query' => $query,
|
|
'type' => $type,
|
|
'movies' => $movies,
|
|
'shows' => $shows,
|
|
'people' => $people,
|
|
]);
|
|
}
|
|
}
|