Pardon the question, as it may be basic, but I seem not to be able to get my headaround it
I am learning the LiveWire UI library(PHP Laravel), and I am following their documentation as part of the learning process.
I was attempting to generate fake data to see the “foreach” loop in action, so that I could gain a better understanding, but it seems as if I am not doing it right, can someone help me please?
View:
livewire.creat-post.blade.php
<div>
@php
$posts = array(
"id" => "bar",
"name" => "foo",
);
@endphp
<h1>Title: "{{$title}}" </h1>
<div>
@foreach ($posts as $post)
<div wire:key="{{ $post->id }}">
<!-- ... -->
</div>
@endforeach
</div>
</div>
Controller:
<?php
namespace AppLivewire;
use LivewireComponent;
class CreatePost extends Component
{
// 2024-12-22 14:45
// as per docs https://livewire.laravel.com/docs/components#setting-properties
public $title = 'Post title... RAD Software Systems' ;
public function render()
{
return view('livewire.create-post');
// return view('livewire.create-post')->with([
// 'author' => Auth::user()->name,
// ]);
}
}
Rendering to localhost browser – see above image : “Localhost: Error Code after Rendering”
I was expecting the foreach loop to print out the array values
1