You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
749 B

7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\Schema;
  5. class BaseModel extends Model
  6. {
  7. //获取某一表的所有字段
  8. public static function getColumnListing($table)
  9. {
  10. return Schema::getColumnListing($table);
  11. }
  12. //过滤不是某一表的字段
  13. public static function filterTableColumn($data, $table)
  14. {
  15. $table_column = Schema::getColumnListing($table);
  16. if(!$table_column)
  17. {
  18. return $data;
  19. }
  20. foreach($data as $k=>$v)
  21. {
  22. if (!in_array($k,$table_column))
  23. {
  24. unset($data[$k]);
  25. }
  26. }
  27. return $data;
  28. }
  29. }