Enquiry::Followups()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sofa\Eloquence\Eloquence;
7
8
class Enquiry extends Model
9
{
10
	protected $table = 'mst_enquiries';
11
12
	protected $fillable = [
13
		'name',
14
		'DOB',
15
		'email',
16
		'address',
17
		'status',
18
		'gender',
19
		'contact',
20
		'pin_code',
21
		'occupation',
22
		'start_by',
23
		'interested_in',
24
		'aim',
25
		'source',
26
		'created_by',
27
    	'updated_by'
28
	];
29
30
	//Eloquence Search mapping
31
    use Eloquence;
32
33
    protected $searchableColumns = [
34
        'name' => 20,
35
        'email' => 20,
36
        'contact' => 20,
37
    ];
38
39
	public function Followups()
40
	{
41
		return $this->hasMany('App\Followup');
42
	}
43
44
	public function createdBy()
45
    {
46
        return $this->belongsTo('App\User','created_by');
47
    }
48
49
    public function updatedBy()
50
    {
51
        return $this->belongsTo('App\User','updated_by');
52
    }
53
54
    public function scopeIndexQuery($query,$sorting_field,$sorting_direction,$drp_start,$drp_end)
55
    {
56
        $sorting_field = ($sorting_field != null ? $sorting_field : 'created_at');
57
        $sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc');
58
59
        if ($drp_start == null or $drp_end == null) 
60
        {
61
            return $query->select('id','name','contact','email','address','gender','created_at','status')->orderBy($sorting_field,$sorting_direction);
62
        }
63
64
        return $query->select('id','name','contact','email','address','gender','created_at','status')->whereBetween('created_at', [$drp_start, $drp_end])->orderBy($sorting_field,$sorting_direction);
65
    }
66
67
    public function scopeOnlyLeads($query)
68
    {
69
       return $query->where('status','=', \constEnquiryStatus::Lead)->orderBy('created_at','desc')->take(10);
70
    }
71
72
}