-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathEventController.php
64 lines (55 loc) · 1.76 KB
/
EventController.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace App\Http\Controllers;
use App\Models\Event;
use Illuminate\Http\Request;
use App\Traits\SchoolSession;
class EventController extends Controller
{
use SchoolSession;
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
if($request->ajax()) {
$currentSchoolSessionId = $this->getSchoolCurrentSession();
$data = Event::whereDate('start', '>=', $request->start)
->whereDate('end', '<=', $request->end)
->where('session_id', $currentSchoolSessionId)
->get(['id', 'title', 'start', 'end']);
return response()->json($data);
}
return view('events.index');
}
public function calendarEvents(Request $request)
{
$currentSchoolSessionId = $this->getSchoolCurrentSession();
$event = null;
switch ($request->type) {
case 'create':
$event = Event::create([
'title' => $request->title,
'start' => $request->start,
'end' => $request->end,
'session_id' => $currentSchoolSessionId
]);
break;
case 'edit':
$event = Event::find($request->id)->update([
'title' => $request->title,
'start' => $request->start,
'end' => $request->end,
]);
break;
case 'delete':
$event = Event::find($request->id)->delete();
break;
default:
break;
}
dd($event);
return response()->json($event);
}
}