atcheck/app/Http/Controllers/User/UserClassesController.php

45 lines
1.4 KiB
PHP
Raw Normal View History

2019-12-01 23:36:12 +01:00
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Subject;
use App\Classes;
class UserClassesController extends Controller
{
public function index($user_id, $groupBy)
{
$subjects = Subject::where('user_id', $user_id)->get();
$subjects_ids = $subjects->pluck('id')->toArray();
$classes = Classes::whereIn('subject_id', $subjects_ids)->get();
$classes_grouped = $classes->groupBy($groupBy);
return view('user.user_classes', ['classes' => $classes, 'classes_grouped' => $classes_grouped, 'subjects' => $subjects, 'grouped_by' => $groupBy]);
}
public function add_classes($user_id, Request $request)
{
$subject_id = $request->input('subject_id');
$date = $request->input('date');
Classes::create([
'subject_id' => $subject_id,
'date' => $date
]);
return redirect(route('user_classes', [$user_id, 'name']));
}
public function delete_classes($user_id, $classes_id, $groupBy)
{
Classes::find($classes_id)->delete();
return redirect(route('user_classes', [$user_id, $groupBy]));
}
public function edit_classes($user_id, $classes_id, $groupBy)
{
Classes::find($classes_id);
return redirect(route('user_classes', [$user_id, $groupBy]));
}
}