Issues (124)

src/Models/DBM_Object.php (1 issue)

1
<?php
2
3
namespace CodexShaper\DBM\Models;
4
5
use CodexShaper\DBM\Contracts\Relationships as RelationshipContract;
6
use CodexShaper\DBM\Traits\Relationships;
7
use Illuminate\Database\Eloquent\Model;
8
9
class DBM_Object extends Model implements RelationshipContract
10
{
11
    use Relationships;
12
13
    /*@var string*/
14
    protected $table = 'dbm_objects';
15
    /*@var array*/
16
    protected $casts = [
17
        'details' => 'array',
18
    ];
19
20
    /**
21
     * Get object fields.
22
     *
23
     * @return \Illuminate\Support\Collection
24
     */
25
    public function fields()
26
    {
27
        return $this->hasMany(DBM_Field::class, 'dbm_object_id');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->hasMany(Co...class, 'dbm_object_id') returns the type Illuminate\Database\Eloquent\Relations\HasMany which is incompatible with the documented return type Illuminate\Support\Collection.
Loading history...
28
    }
29
30
    /**
31
     * Get all fields.
32
     *
33
     * @param string $order_by
34
     * @param string $direction
35
     *
36
     * @return \Illuminate\Support\Collection
37
     */
38
    public function allFields($order_by = 'order', $direction = 'ASC')
39
    {
40
        return $this->fields()->orderBy($order_by, $direction)->get();
41
    }
42
43
    /**
44
     * Get Create fields.
45
     *
46
     * @param string $order_by
47
     * @param string $direction
48
     *
49
     * @return \Illuminate\Support\Collection
50
     */
51
    public function createFields($order_by = 'order', $direction = 'ASC')
52
    {
53
        return $this->fields()->where('create', 1)->orderBy($order_by, $direction)->get();
54
    }
55
56
    /**
57
     * Get Browse fields.
58
     *
59
     * @param string $order_by
60
     * @param string $direction
61
     *
62
     * @return \Illuminate\Support\Collection
63
     */
64
    public function readFields($order_by = 'order', $direction = 'ASC')
65
    {
66
        return $this->fields()->where('read', 1)->orderBy($order_by, $direction)->get();
67
    }
68
69
    /**
70
     * Get Edit fields.
71
     *
72
     * @param string $order_by
73
     * @param string $direction
74
     *
75
     * @return \Illuminate\Support\Collection
76
     */
77
    public function editFields($order_by = 'order', $direction = 'ASC')
78
    {
79
        return $this->fields()->where('edit', 1)->orderBy($order_by, $direction)->get();
80
    }
81
82
    /**
83
     * Get Delete fields.
84
     *
85
     * @param string $order_by
86
     * @param string $direction
87
     *
88
     * @return \Illuminate\Support\Collection
89
     */
90
    public function deleteFields($order_by = 'order', $direction = 'ASC')
91
    {
92
        return $this->fields()->where('delete', 1)->orderBy($order_by, $direction)->get();
93
    }
94
}
95