BaseModel.php 618 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. use Illuminate\Database\Eloquent\Model;
  5. class BaseModel extends Model
  6. {
  7. public function timeFormat($time)
  8. {
  9. $time = date_create($time);
  10. return date_format($time,'Y-m-d').'T'.date_format($time,'H:i:s');
  11. }
  12. public function belongFormat($belong)
  13. {
  14. return explode(',', $belong);
  15. }
  16. public function getFromMenuId($menu_id)
  17. {
  18. return DB::table($this->getTable())
  19. ->whereRaw('find_in_set('.$menu_id.', belong)')
  20. ->orderBy('created_at', 'desc')
  21. ->get();
  22. }
  23. }