Passed
Push — main ( bfff7a...f85971 )
by PRATIK
13:07
created

UserPreferences::mount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pratiksh\Adminetic\Http\Livewire\Admin\User;
4
5
use App\Models\User;
0 ignored issues
show
Bug introduced by
The type App\Models\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Livewire\Component;
7
use Pratiksh\Adminetic\Models\Admin\Preference;
8
9
class UserPreferences extends Component
10
{
11
    public $user;
12
13
    public $preference;
14
15
    public $enabled;
16
17
    protected $listeners = ['preference_changed' => 'preferenceChanged'];
18
19
    public function mount(User $user, Preference $preference)
20
    {
21
        $this->user = $user;
22
        $this->preference = $preference;
23
        $this->enabled = $preference->pivot->enabled;
0 ignored issues
show
Bug introduced by
The property pivot does not seem to exist on Pratiksh\Adminetic\Models\Admin\Preference. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
24
    }
25
26
    public function preferenceChanged(User $user, Preference $preference)
27
    {
28
        $user->preferences()->updateExistingPivot($preference->id, ['enabled' => !$this->enabled], false);
29
30
        $this->preference = $preference;
31
        $this->enabled = !$this->enabled;
32
    }
33
34
    public function render()
35
    {
36
        return view('adminetic::livewire.admin.user.user-preferences');
37
    }
38
}
39