12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Models;
- use App\User;
- use Illuminate\Database\Eloquent\Model;
- class Base extends Model
- {
- public static function formatValidator($validator)
- {
- return current($validator->errors()->messages())[0];
- }
- public static function getUserInfo()
- {
- $user_info = User::getCurrentUser();
- return $user_info;
- }
- public static function getUserId()
- {
- $user_info = self::getUserInfo();
- $user_id = $user_info->id;
- return $user_id;
- }
- public static function endDataPut($data)
- {
- if (empty($data)) {
- $data = (object) array();
- }
- return $data;
- }
- public static function formatImgUrl($data, $params = array())
- {
- if (!$params || empty($data)) {
- return $data;
- }
- foreach ($data as $item) {
- foreach ($params as $v) {
- $item->$v = env('IMAGE_URL') . $item->$v;
- }
- }
- return $data;
- }
- public static function getDevice()
- {
- $device = 1; //android
- $user_agent = $_SERVER['HTTP_USER_AGENT'];
- if (strpos($user_agent, 'iPhone') || strpos($user_agent, 'iphone')) {
- $device = 2; //ios
- }
- return $device;
- }
- }
|