|
1
|
|
|
<?php namespace App\Models; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
6
|
|
|
|
|
7
|
|
|
class Products extends Model { |
|
8
|
|
|
|
|
9
|
|
|
use SoftDeletes; |
|
10
|
|
|
|
|
11
|
|
|
protected $table = 'products'; |
|
12
|
|
|
public $timestamps = true; |
|
13
|
|
|
protected $dates = ['deleted_at']; |
|
14
|
|
|
public $primaryKey = 'product_id'; |
|
15
|
|
|
|
|
16
|
|
|
public static $validationRules = [ |
|
17
|
|
|
|
|
18
|
|
|
'category' => 'required|integer|min:0', |
|
19
|
|
|
'name' => 'required|name', |
|
20
|
|
|
'description' => 'max:250', |
|
21
|
|
|
'price' => 'required|numeric|min:0', |
|
22
|
|
|
'quantity' => 'required|integer|min:0' |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
public function category() { |
|
26
|
|
|
|
|
27
|
|
|
return $this->belongsTo('Categories', 'category_id', 'category_id'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function scopeGroup($query, $groupID) { |
|
31
|
|
|
|
|
32
|
|
|
$query->select('products.*') |
|
33
|
|
|
->join('categories', 'categories.category_id', '=', 'products.category_id') |
|
34
|
|
|
->where('group_id', $groupID); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// Still used by the App Component. |
|
38
|
|
|
public static function getSpecificExtended($id) { |
|
39
|
|
|
|
|
40
|
|
|
$query = 'SELECT p.* |
|
41
|
|
|
FROM products p |
|
42
|
|
|
INNER JOIN categories c ON p.category_id = c.category_id |
|
43
|
|
|
WHERE c.category_id = p.category_id |
|
44
|
|
|
AND c.group_id = ? |
|
45
|
|
|
AND p.product_id = ?'; |
|
46
|
|
|
|
|
47
|
|
|
$products = DB::select($query, [ Session::get('groupID'), $id ]); |
|
48
|
|
|
|
|
49
|
|
|
if( count($products) == 0 ) |
|
50
|
|
|
return null; |
|
51
|
|
|
|
|
52
|
|
|
return $products[0]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |