Passed
Push — master ( e09305...160681 )
by Thomas
08:46
created

ShowStudentListOperation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setupShowStudentListRoutes() 0 6 1
A setupShowStudentListDefaults() 0 7 1
A showstudentlist() 0 12 2
1
<?php
2
3
namespace App\Http\Controllers\Admin\Operations;
4
5
use App\Models\Course;
6
use Illuminate\Support\Facades\Gate;
7
use Illuminate\Support\Facades\Route;
8
9
trait ShowStudentListOperation
10
{
11
    /**
12
     * Define which routes are needed for this operation.
13
     *
14
     * @param string $segment    Name of the current entity (singular). Used as first URL segment.
15
     * @param string $routeName  Prefix of the route name.
16
     * @param string $controller Name of the current CrudController.
17
     */
18
    protected function setupShowStudentListRoutes($segment, $routeName, $controller)
19
    {
20
        Route::get($segment.'/{id}/show', [
21
            'as' => $routeName.'.showstudentlist',
22
            'uses' => $controller.'@showstudentlist',
23
            'operation' => 'showstudentlist',
24
        ]);
25
    }
26
27
    /**
28
     * Add the default settings, buttons, etc that this operation needs.
29
     */
30
    protected function setupShowStudentListDefaults()
31
    {
32
        $this->crud->allowAccess(['showstudentphotoroster']);
33
        $this->crud->setOperationSetting('setFromDb', true);
34
35
        $this->crud->operation('showstudentphotoroster', function () {
36
            $this->crud->loadDefaultOperationSettingsFromConfig();
37
        });
38
39
        // $this->crud->operation('list', function () {
40
        //     $this->crud->addButton('line', 'showstudentphotoroster', 'view', 'crud::buttons.studentRoster', 'beginning');
41
        // });
42
    }
43
44
    /**
45
     * Show the view for performing the operation.
46
     */
47
    public function showstudentlist($id)
48
    {
49
        $course = Course::findOrFail($id);
50
        // The current is not allowed to view the page
51
        if (Gate::forUser(backpack_user())->denies('view-course', $course)) {
52
            abort(403);
53
        }
54
55
        return view('courses/show', [
56
            'course' => $course,
57
            'enrollments' => $course->enrollments()->with('student')->get(),
58
            'widget' => ['course' => $course ],
59
        ]);
60
    }
61
}
62