progress
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user