%PDF- %PDF-
Direktori : /proc/self/root/var/www/html/app/Models/ |
Current File : //proc/self/root/var/www/html/app/Models/User.php |
<?php namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use App\Models\Concerns\HasMeta; use Illuminate\Support\Carbon; use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable, HasMeta, HasRoles; /** * The attributes that are mass assignable. * * @var string[] */ protected $fillable = [ 'name', 'email', 'phone', 'password', 'status', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'date_j' => 'datetime:d/m/Y' ]; protected $appends = [ 'date_j' ]; public function meta() { return $this->hasMany(Usermeta::class); } public function getDateJAttribute() { if( $this->meta->date_j ) { try { $date = @Carbon::createFromFormat('Y-m-d', $this->meta->date_j); } catch (\Throwable $th) { return null; } if( $date ) { return $date->format('d/m/Y'); } } return null; } public function commandes() { return $this->hasMany(Commande::class, 'commercial_id', 'id'); } public function month_commandes() { $m = gmdate('m'); $m1 = $m < 12 ? $m + 1 : 1; $y = gmdate('Y'); $ye = $y + 1; $y1 = $m1 < $m ? $y + 1 : $y; $start_month = Carbon::createFromFormat('d-m-Y H:i:s', "01-{$m}-{$y} 00:00:00"); $end_month = Carbon::createFromFormat('d-m-Y H:i:s', "01-{$m1}-{$y1} 00:00:00"); return $this->hasMany(Commande::class, 'commercial_id', 'id')->whereBetween('created_at', [$start_month->format('Y-m-d')." 00:00:00", $end_month->format('Y-m-d')." 00:00:00"]); } }