Bought.php 767 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Models;
  3. class Bought extends Model
  4. {
  5. protected $connection = "default";
  6. protected $table = "bought";
  7. public function renew_date()
  8. {
  9. return date("Y-m-d H:i:s", $this->attributes['renew']);
  10. }
  11. public function datetime()
  12. {
  13. return date("Y-m-d H:i:s", $this->attributes['datetime']);
  14. }
  15. public function user()
  16. {
  17. $user = User::where("id", $this->attributes['userid'])->first();
  18. if ($user == null) {
  19. Bought::where('id', '=', $this->attributes['id'])->delete();
  20. return null;
  21. } else {
  22. return $user;
  23. }
  24. }
  25. public function shop()
  26. {
  27. return Shop::where("id", $this->attributes['shopid'])->first();
  28. }
  29. }