Completed
Push — master ( 5d49af...15d463 )
by Jeff
06:07
created

Order::searchOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Shop\Orders;
4
5
use App\Shop\Addresses\Address;
6
use App\Shop\Couriers\Courier;
7
use App\Shop\Customers\Customer;
8
use App\Shop\OrderStatuses\OrderStatus;
9
use App\Shop\Products\Product;
10
use Illuminate\Database\Eloquent\Model;
11
use Nicolaslopezj\Searchable\SearchableTrait;
12
13
class Order extends Model
14
{
15
    use SearchableTrait;
16
17
    /**
18
     * Searchable rules.
19
     *
20
     * Columns and their priority in search results.
21
     * Columns with higher values are more important.
22
     * Columns with equal values have equal importance.
23
     *
24
     * @var array
25
     */
26
    protected $searchable = [
27
        'columns' => [
28
            'customers.name' => 10,
29
            'orders.reference' => 8,
30
            'products.name' => 5
31
        ],
32
        'joins' => [
33
            'customers' => ['customers.id', 'orders.customer_id'],
34
            'order_product' => ['orders.id', 'order_product.order_id'],
35
            'products' => ['products.id', 'order_product.product_id'],
36
        ],
37
        'groupBy' => ['orders.id']
38
    ];
39
40
    /**
41
     * The attributes that are mass assignable.
42
     *
43
     * @var array
44
     */
45
    protected $fillable = [
46
        'reference',
47
        'courier_id', // @deprecated
48
        'courier',
49
        'customer_id',
50
        'address_id',
51
        'order_status_id',
52
        'payment',
53
        'discounts',
54
        'total_products',
55
        'total',
56
        'tax',
57
        'total_paid',
58
        'invoice',
59
        'label_url',
60
        'tracking_number'
61
    ];
62
63
    /**
64
     * The attributes that should be hidden for arrays.
65
     *
66
     * @var array
67
     */
68
    protected $hidden = [];
69
70
    /**
71
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
72
     */
73
    public function products()
74
    {
75
        return $this->belongsToMany(Product::class)
76
                    ->withPivot([
77
                        'quantity',
78
                        'product_name',
79
                        'product_sku',
80
                        'product_description',
81
                        'product_price'
82
                    ]);
83
    }
84
85
    /**
86
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
87
     */
88
    public function customer()
89
    {
90
        return $this->belongsTo(Customer::class);
91
    }
92
93
    /**
94
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
95
     */
96
    public function courier()
97
    {
98
        return $this->belongsTo(Courier::class);
99
    }
100
101
    /**
102
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
103
     */
104
    public function address()
105
    {
106
        return $this->belongsTo(Address::class);
107
    }
108
109
    /**
110
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
111
     */
112
    public function orderStatus()
113
    {
114
        return $this->belongsTo(OrderStatus::class);
115
    }
116
117
    /**
118
     * @param string $term
119
     *
120
     * @return mixed
121
     */
122
    public function searchForOrder(string $term)
123
    {
124
        return self::search($term);
125
    }
126
}
127