ldc-mesbr-app/app/Contact.php
Thibault Richy dc240f928f Retours 03
2019-02-28 17:05:24 +01:00

92 lines
1.9 KiB
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
/**
* @var string
*/
const CREATED_AT = 'contact_createdate';
/**
* @var string
*/
const UPDATED_AT = 'contact_updatedate';
/**
* @var string
*/
protected $table = 'contact';
/**
* @var string
*/
protected $primaryKey = 'contact_id';
/**
* @var array
*/
protected $fillable = [
'contact_ref',
'contact_prenom',
'contact_nom',
'contact_email',
'contact_cp',
'contact_ville',
'contact_country',
];
/**
* OneToMany
* Contact -> Mur
*/
public function murs()
{
return $this->hasMany('App\Mur', 'mur_contactId', 'contact_id');
}
/**
* OneToMany
* Contact -> Panier
*/
public function paniers()
{
return $this->hasMany('App\Panier', 'panier_contactId', 'contact_id');
}
/**
* ManyToOne
* Contact -> Site
*/
public function site()
{
return $this->belongsTo('App\Site', 'contact_siteId');
}
public function scopeSearchName($query, $name) {
if ($name) $query->where('contact_nom', 'like', '%'.$name.'%');
}
public function scopeSearchFirstname($query, $firstname) {
if ($firstname) $query->where('contact_prenom', 'like', '%'.$firstname.'%');
}
public function scopeSearchEmail($query, $email) {
if ($email) $query->where('contact_email', 'like', '%'.$email.'%');
}
public function scopeSearchVille($query, $ville) {
if ($ville) $query->where('contact_ville', 'like', '%'.$ville.'%');
}
public function scopeSearchCp($query, $cp) {
if ($cp) $query->where('contact_cp', 'like', '%'.$cp.'%');
}
public function scopeSearchCountry($query, $country) {
if ($country) $query->where('contact_country', $country);
}
}