transcriptor-web/app/Http/Controllers/VideoController.php
2025-04-05 15:58:14 +02:00

47 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Video;
class VideoController extends Controller
{
/**
* Display a listing of videos.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function getVideos(Request $request)
{
// Start a query on the Video model
$query = Video::with(['clips', 'transcriptions', 'channel']);
// Filter by channel_id if provided
if ($request->has('channel_ids')) {
$query->whereIn('channel_id', $request->input('channel_ids'));
}
// Filter by language if provided
// Assuming that the Video model has a relationship to Channel
// and the Channel model has a 'language' attribute
if ($request->has('languages')) {
$languages = $request->input('languages');
$query->whereHas('channel', function ($q) use ($languages) {
$q->whereIn('language', $languages);
});
}
if($request->has('start_date') && $request->has('end_date')) {
$query->whereBetween('external_date', [$request->input('start_date'), $request->input('end_date')]);
}
// Retrieve the videos (you can add pagination if desired)
$videos = $query->orderBy('external_date', 'desc')->get();
// Return the videos as a JSON response
return response()->json($videos);
}
}