app\models\Artist::getInfo PHP Метод

getInfo() публичный Метод

Get extra information about the artist from Last.fm.
public getInfo ( ) : array | false
Результат array | false
    public function getInfo()
    {
        if ($this->isUnknown()) {
            return false;
        }
        $info = Lastfm::getArtistInfo($this->name);
        // If our current artist has no image, and Last.fm has one, copy the image for our local use.
        if (!$this->image && is_string($image = array_get($info, 'image')) && ini_get('allow_url_fopen')) {
            try {
                $extension = explode('.', $image);
                $fileName = uniqid() . '.' . trim(strtolower(last($extension)), '. ');
                $coverPath = app()->publicPath() . '/public/img/artists/' . $fileName;
                file_put_contents($coverPath, file_get_contents($image));
                $this->update(['image' => $fileName]);
                $info['image'] = $this->image;
            } catch (Exception $e) {
                Log::error($e);
            }
        }
        return $info;
    }

Usage Example

Пример #1
0
 /**
  * Get extra information about an artist via Last.fm.
  *
  * @param Artist $artist
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function getInfo(Artist $artist)
 {
     return response()->json($artist->getInfo());
 }