Issues (364)

app/Models/User.php (4 issues)

1
<?php
2
3
namespace App\Models;
4
5
use App\Notifications\ResetPassword;
6
use Illuminate\Auth\Passwords\CanResetPassword;
7
use Laravel\Cashier\Billable;
8
use LaravelEnso\Avatars\Models\Avatar;
0 ignored issues
show
This use statement conflicts with another class in this namespace, App\Models\Avatar. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use LaravelEnso\Users\Models\User as CoreUser;
10
11
class User extends CoreUser
12
{
13
    use Billable, CanResetPassword;
0 ignored issues
show
The trait Laravel\Cashier\Billable requires some properties which are not provided by App\Models\User: $invoices, $tax_exempt, $name, $invoice_settings, $email, $refunds, $data, $invoiceItems, $paymentIntents, $promotionCodes, $default_source, $sessions, $balance, $brand, $setupIntents, $paymentMethods, $last4, $paid, $customer, $type, $card, $default_payment_method, $discount, $customers, $payment_intent, $trial_ends_at, $billingPortal, $phone, $subscriptions
Loading history...
The trait Illuminate\Auth\Passwords\CanResetPassword requires the property $email which is not provided by App\Models\User.
Loading history...
14
    protected $fillable = [
15
        'name',
16
        'email',
17
        'password',
18
        'person_id',
19
        'group_id',
20
        'role_id',
21
        'is_active',
22
    ];
23
24
    public function social()
25
    {
26
        return $this->hasMany(UserSocial::class, 'user_id', 'id');
27
    }
28
29
    public function avatar()
30
    {
31
        return $this->hasOne(Avatar::class, 'user_id', 'id');
32
    }
33
34
    public function getNameAttribute()
35
    {
36
        return $this->person?->name;
0 ignored issues
show
The property person does not exist on App\Models\User. Did you mean person_id?
Loading history...
37
    }
38
39
    public function hasSocialLinked($service): bool
40
    {
41
        return (bool) $this->social->where('service', $service)->count();
42
    }
43
44
    public function messages()
45
    {
46
        return $this->hasMany(Message::class);
47
    }
48
49
    public function convOne()
50
    {
51
        return $this->belongsTo(Conversation::class, 'user_one');
52
    }
53
54
    public function convTwo()
55
    {
56
        return $this->belongsTo(Conversation::class, 'user_two');
57
    }
58
59
    public function conversations()
60
    {
61
        return $this->convOne->merage($this->convTwo);
62
    }
63
64
    public function sendPasswordResetNotification($token)
65
    {
66
        $this->notify(new ResetPassword($token));
67
    }
68
//    public function avatar()
69
//    {
70
//        return $this->hasOne(\Avatar::class);
71
//    }
72
73
//    private function getIdAttribute($value='')
74
//    {
75
//       $this->id=1;
76
//    }
77
}
78