-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTVSeriesController.php
39 lines (29 loc) · 1.32 KB
/
TVSeriesController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\TvSerie;
use App\Models\TvSerieInterval;
use Illuminate\Http\Request;
class TVSeriesController extends Controller {
public function index(Request $request) {
$search = $request->input('search');
$date = $request->input('date');
$time = $request->input('time');
$date = $date ? $date : date("Y/m/d");
$time = $time ? $time : date("H:i");
$date_time = date("Y-m-d H:i", strtotime($date . " " . $time));
$week_day = date("w", strtotime($date_time)) + 1;
$order_by = "concat(DATE_ADD(date('$date_time'), INTERVAL abs($week_day-if(week_day < $week_day,week_day + 7,week_day)) DAY),' ',show_time)";
if ($search) {
$tvSerie = TvSerie::where("title", "LIKE", "%$search%")->get()->pluck('id')->toArray();
$intervals = TvSerieInterval::whereIn("id_tv_series", $tvSerie)->orderByRaw("'$date_time' > $order_by")->orderByRaw($order_by);
} else {
$intervals = TvSerieInterval::orderByRaw("'$date_time' > $order_by")->orderByRaw($order_by);
}
$data['intervals'] = $intervals->get();
$data['search'] = $search;
$data['date'] = $date;
$data['time'] = $time;
return view('tv-series', $data);
}
}