2017-05-18 6 views
0

私はLaravel PHP Frameworkを使用していますが、tmdbパッケージを使用したいと思います。Laravel 5.4のtmdb APIからリリース日を取得するには?

jsonでリリース日を見ることができます。ここでは、スクリーンショット

http://prntscr.com/f98ydy

あるしかし、私はコードでタイトルを得ることができますように私は私の見解では、これをしたい:

{!! $movie->getTitle() !!} 

リリース日を取得するにはどのように?私はまた、そのコード

{!! $movie->getReleaseDate() !!} 

しかし、私に

Object of class DateTime could not be converted to string (View: C:\xampp\htdocs\hallofsound\resources\views\welcome.blade.php) 

はここに私の完全なJSON出力

ResultCollection {#1811 ▼ 
    -page: 1 
    -totalPages: 36 
    -totalResults: 702 
    #data: array:20 [▼ 
    "000000004255a5960000000012a0a3a3" => Movie {#1816 ▼ 
     -adult: false 
     -backdropPath: "/aJn9XeesqsrSLKcHfHP4u5985hn.jpg" 
     -backdrop: BackdropImage {#1327 ▶} 
     -belongsToCollection: null 
     -budget: null 
     -genres: Genres {#1832 ▶} 
     -homepage: null 
     -id: 283995 
     -imdbId: null 
     -originalTitle: "Guardians of the Galaxy Vol. 2" 
     -originalLanguage: "en" 
     -overview: "The Guardians must fight to keep their newfound family together as they unravel the mysteries of Peter Quill's true parentage." 
     -popularity: 115.058584 
     -poster: PosterImage {#1837 ▶} 
     -posterPath: "/y4MBh0EjBlMuOzv9axM4qJlmhzz.jpg" 
     -productionCompanies: GenericCollection {#1331 ▶} 
     -productionCountries: GenericCollection {#1830 ▶} 
     -releaseDate: DateTime {#1840 ▶} 
     -revenue: null 
     -runtime: null 
     -spokenLanguages: GenericCollection {#1828 ▶} 
     -status: null 
     -tagline: null 
     -title: "Guardians of the Galaxy Vol. 2" 
     -voteAverage: 7.6 
     -voteCount: 1539 
     #alternativeTitles: GenericCollection {#1826 ▶} 
     #changes: GenericCollection {#1829 ▶} 
     #credits: CreditsCollection {#1821 ▶} 
     #images: Images {#1319 ▶} 
     #keywords: GenericCollection {#1824 ▶} 
     #lists: GenericCollection {#1820 ▶} 
     #releases: GenericCollection {#1316 ▶} 
     #release_dates: GenericCollection {#1822 ▶} 
     #similar: GenericCollection {#1819 ▶} 
     #translations: GenericCollection {#1825 ▶} 
     #reviews: null 
     #videos: Videos {#1831 ▶} 
    } 
    "000000004255a5a00000000012a0a3a3" => Movie {#1838 ▶} 
    "000000004255a5c90000000012a0a3a3" => Movie {#1863 ▶} 
    "000000004255a5ee0000000012a0a3a3" => Movie {#1888 ▶} 
    "000000004255a5f70000000012a0a3a3" => Movie {#1913 ▶} 
    "000000004255a51f0000000012a0a3a3" => Movie {#1937 ▶} 
    "000000004255a5240000000012a0a3a3" => Movie {#1962 ▶} 
    "000000004255a54d0000000012a0a3a3" => Movie {#1987 ▶} 
    "000000004255a5550000000012a0a3a3" => Movie {#2011 ▶} 
    "000000004255a57d0000000012a0a3a3" => Movie {#2035 ▶} 
    "000000004255aa840000000012a0a3a3" => Movie {#2058 ▶} 
    "000000004255aaac0000000012a0a3a3" => Movie {#2082 ▶} 
    "000000004255aab50000000012a0a3a3" => Movie {#2107 ▶} 
    "000000004255aadb0000000012a0a3a3" => Movie {#2133 ▶} 
    "000000004255aae00000000012a0a3a3" => Movie {#2158 ▶} 
    "000000004255aa080000000012a0a3a3" => Movie {#2182 ▶} 
    "000000004255aa110000000012a0a3a3" => Movie {#2207 ▶} 
    "000000004255aa360000000012a0a3a3" => Movie {#2232 ▶} 
    "000000004255aa5f0000000012a0a3a3" => Movie {#2257 ▶} 
    "000000004255aa640000000012a0a3a3" => Movie {#2282 ▶} 
    ] 
} 

答えて

1

JSON応答が収集されているこのエラーを示してみました。だからあなたはそれをループする必要があります。

foreach($movies as $movie) 
{ 
    var_dump($movie->getTitle()); 
} 

またDateTimeオブジェクトを返しますgetReleaseDate方法:このような何かにそうかもしれないhere

を参照してください。

$date = new DateTime($movie->getReleaseDate()); 
$result = $date->format('Y-m-d H:i:s'); 

またはLaravelで、あなたがこれを行うことができます:それをフォーマットするには、おそらくこのような何かを行うことができます

{!! $movie->getReleaseDate()->format('Y-m-d H:i:s') !!} 
+0

のgetTitle()が機能していますが、私は –

+0

が編集見ることができますどのようにRELEASEDATE必要私の回答。 – Mozammil

+0

作業コードを編集する –

関連する問題