47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Subject;
|
|
use App\Classes;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class UserClassesController extends Controller
|
|
{
|
|
public function index($groupBy='name')
|
|
{
|
|
$user_id = Auth::id();
|
|
$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(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'));
|
|
}
|
|
|
|
public function delete_classes($classes_id)
|
|
{
|
|
Classes::find($classes_id)->delete();
|
|
return redirect(route('user_classes'));
|
|
}
|
|
|
|
public function edit_classes($classes_id)
|
|
{
|
|
Classes::find($classes_id);
|
|
return redirect(route('user_classes'));
|
|
}
|
|
}
|