Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. id | name |
  2.  
  3. id | typesoin_id | animal_id | datedusoin
  4.  
  5. public function soinsvetos() {
  6. return $this->hasMany(Soinsveto::class, 'animal_id');
  7. }
  8.  
  9. public function animal()
  10. {
  11. return $this->belongsTo(Animal::class, 'animal_id')->withTrashed();
  12. }
  13.  
  14. public function compose(View $view)
  15. {
  16.  
  17. foreach (AppAnimal::get()
  18. ->all() as $animal) {
  19.  
  20. $soins = AppSoinsveto::with('typesoin')
  21. ->where('animal_id', $animal->id)
  22. ->where(function ($q) { /// 1 = primovaccin et 2 = vaccins annuels
  23. $q->where('typesoin_id', '=', '2')
  24. ->orWhere('typesoin_id', '=', '1');
  25. })
  26. ->orderBy('datedusoin', 'desc')
  27. ->get()
  28. ->first();
  29. if ($soins) {
  30.  
  31. if ($soins->typesoin_id == '1' && $soins->datedusoin < Carbon::now()->subMonths(1)) {
  32. $crudFieldValue = Carbon::parse($soins->getOriginal('datedusoin'))->addyear(1)->toDateString();
  33.  
  34. }
  35. if ($soins->typesoin_id == '2' && $soins->datedusoin < Carbon::now()->subYears(1)) {
  36. $crudFieldValue = Carbon::parse($soins->getOriginal('datedusoin'))->addyear(1)->toDateString();
  37.  
  38. }
  39.  
  40. }
  41. $notif[] = [
  42. 'title' => $soins->typesoin->nomsoin,
  43. 'start' => $crudFieldValue,
  44. 'nomanimal' => $animal->nom,
  45. ];
  46. }
  47. $view->with('notif', $notif);
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement