Controller:Schleife durch JSON-Array in PHP Laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class welcomeController extends Controller
{
public function welcome() {
$cards = json_decode('[{
"id": 1,
"name ": "a",
"class": "class1"
}, {
"id": 2,
"name ": "b",
"class": "class2"
}]');
return view('welcome', compact('cards'));
}
}
welcome.blade.php
@foreach($cards as $card)
<p>{{ $card->name }} </p>
<p>{{ $card->class }} </p>
@endforeach
Ich bin Neu bei PHP Larav el. Bitte helfen Sie mir, die richtige Lösung dafür zu finden. Danke.
Große Beobachtung, vielen Dank. Das hat funktioniert. – Kartik