diff --git a/app/Article.php b/app/Article.php index 4a0c5eaaa..7489755ce 100644 --- a/app/Article.php +++ b/app/Article.php @@ -6,6 +6,7 @@ use App\Tools\Markdowner; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Str; class Article extends Model { @@ -124,7 +125,7 @@ public function setTitleAttribute($value) $this->attributes['title'] = $value; if (!config('services.youdao.appKey') || !config('services.youdao.appSecret')) { - $this->setUniqueSlug($value, str_random(5)); + $this->setUniqueSlug($value, Str::random(5)); } else { $this->setUniqueSlug(translug($value), ''); } @@ -138,7 +139,7 @@ public function setTitleAttribute($value) */ public function setUniqueSlug($value, $extra) { - $slug = str_slug($value.'-'.$extra); + $slug = Str::slug($value.'-'.$extra); if (static::whereSlug($slug)->exists()) { $this->setUniqueSlug($slug, (int) $extra + 1); diff --git a/app/Http/Controllers/Api/UploadController.php b/app/Http/Controllers/Api/UploadController.php index ea2f3e2e1..657cb83d8 100644 --- a/app/Http/Controllers/Api/UploadController.php +++ b/app/Http/Controllers/Api/UploadController.php @@ -4,6 +4,7 @@ use Illuminate\Http\Request; use App\Http\Requests\ImageRequest; +use Illuminate\Support\Str; class UploadController extends ApiController { @@ -45,7 +46,7 @@ public function uploadForManager(Request $request) ? $request->get('name').'.'.explode('/', $file->getClientMimeType())[1] : $file->getClientOriginalName(); - $path = str_finish($request->get('folder'), '/'); + $path = Str::finish($request->get('folder'), '/'); if ($this->manager->checkFile($path.$fileName)) { return $this->response->withBadRequest('This File exists.'); diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index efcf95ea9..f2b8771a8 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -4,6 +4,7 @@ use App\Scopes\StatusScope; use App\User; +use Illuminate\Support\Str; use Image; use Illuminate\Http\Request; use App\Http\Requests\UserRequest; @@ -61,7 +62,7 @@ public function store(UserRequest $request) { $data = array_merge($request->all(), [ 'password' => bcrypt($request->get('password')), - 'confirm_code' => str_random(64), + 'confirm_code' => Str::random(64), ]); \DB::transaction(function () use ($request, $data) { diff --git a/app/Support/Transform.php b/app/Support/Transform.php index 8822eba2e..1cf0e3ee0 100644 --- a/app/Support/Transform.php +++ b/app/Support/Transform.php @@ -2,6 +2,7 @@ namespace App\Support; +use Illuminate\Support\Arr; use League\Fractal\Manager; use App\Transformers\EmptyTransformer; use League\Fractal\TransformerAbstract; @@ -42,8 +43,8 @@ public function __construct(Manager $fractal) * * @param $data * @param TransformerAbstract|null $transformer - * * @return array + * @throws \Exception */ public function collection($data, TransformerAbstract $transformer = null) { @@ -63,8 +64,8 @@ public function collection($data, TransformerAbstract $transformer = null) * * @param $data * @param TransformerAbstract|null $transformer - * * @return array + * @throws \Exception */ public function item($data, TransformerAbstract $transformer = null) { @@ -127,7 +128,7 @@ protected function hasDefaultTransformer($className) protected function getClassName($object) { if ($object instanceof LengthAwarePaginator || $object instanceof Collection) { - return get_class(array_first($object)); + return get_class(Arr::first($object)); } if (!is_string($object) && !is_object($object)) {