Issues (350)

app/Http/Controllers/ConfigController.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\UpdateConfigRequest;
6
use App\Models\Config;
7
use App\Models\Period;
8
9
class ConfigController extends Controller
10
{
11
    public function get()
12
    {
13
        if (! backpack_user()->hasPermissionTo('courses.edit')) {
0 ignored issues
show
The method hasPermissionTo() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        if (! backpack_user()->/** @scrutinizer ignore-call */ hasPermissionTo('courses.edit')) {
Loading history...
14
            abort(403);
15
        }
16
17
        $currentPeriod = Period::get_default_period();
18
        $enrollmentsPeriod = Period::get_enrollments_period();
19
        $availablePeriods = Period::all();
20
21
        return view('admin.defaultPeriodsSelection', compact('currentPeriod', 'enrollmentsPeriod', 'availablePeriods'));
22
    }
23
24
    public function update(UpdateConfigRequest $request)
25
    {
26
        if (! backpack_user()->hasPermissionTo('courses.edit')) {
27
            abort(403);
28
        }
29
30
        Config::where('name', 'current_period')->first()->update([
31
            'value' => $request->currentPeriod,
32
        ]);
33
34
        Config::where('name', 'default_enrollment_period')->first()->update([
35
            'value' => $request->enrollmentsPeriod,
36
        ]);
37
38
        return redirect()->to('/');
39
    }
40
}
41