我想从 riot api 调用特定数据。
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Request;
class champion extends Controller
{
public function Aatrox()
{
$data = Http::get('https://ddragon.leagueoflegends.com/cdn/11.16.1/data/en_US/champion/Aatrox.json')->json();
return view('test',compact('data'));
}
}
路线
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\champion;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/aatrox', [champion::class,'Aatrox']);
看法
AAtrox<br/>
{{print_r($data)}}
但是当我改变我的观点时
AAtrox<br/>
@foreach ($data as $item)
{{$item->data->name}}
@endforeach
我正在尝试获取非对象的属性“数据”
生病不胜感激任何建议。
我想做的是
"name":"Aatrox","title":"黑暗之刃","image":{"full":"Aatrox.png",
我只想得到这个名称标题和图像部分。