Как использовать страницу в Laravel LiveWire с функциональной версией, а не классомPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Как использовать страницу в Laravel LiveWire с функциональной версией, а не классом

Сообщение Anonymous »

Я просто пытаюсь следовать за Bootcamp для Laravel с помощью LiveWire: https://bootcamp.laravel.com/livewire/showing-chirps, так что у него есть примечание:

Возвращение всех чирп сразу не будет масштабироваться в производстве. Взгляните на мощную страницу Pagination
Laravel для повышения производительности. />
< /code>


@foreach ($chirps as $chirp)


...

@endforeach



< /code>
Reading the documentation it only include examples for the "class version" https://livewire.laravel.com/docs/pagin ... asic-usage like:
use Livewire\WithPagination;
use Livewire\Volt\Component;
use App\Models\Post;

new class extends Component {
use WithPagination;

public function with(): array
{
return [
'posts' => Post::paginate(10),
];
}
}
< /code>
So I already tried importing the trait in the view like:
use Livewire\WithPagination;

$getChirps = fn () => $this->chirps = Chirp::paginate(10);
< /code>
or
$getChirps = function () {
return $this->chirps = Chirp::with('user')->paginate(15);
};
< /code>
And I'm getting the next error:

Property type not supported in Livewire for property:
[{"current_page":1,"data":[{"id":1,"user_id":1,"message":"This chirp
is a
test","created_at":"2025-02-14T03:24:24.000000Z","updated_at":"2025-02-14T03:24:24.000000Z","user":{"id":1,"name":"Roberto","email":"robertohdll@gmail.com","email_verified_at":null,"created_at":"2025-02-09T14:10:52.000000Z","updated_at":"2025-02-09T14:10:52.000000Z"}}],"first_page_url":"http://127.0.0.1:8000/chirps?page=1","f ... =1","links":[{"url":null,"label":"«
Previous","active":false},{"url":"http://127.0.0.1:8000/chirps?page=1","l ... bel":"Next
»","active":false}],"next_page_url":null,"path":"http://127.0.0.1:8000/chirps","per_page ... ,"total":1}]

So the query to the DB is working and is getting the pages, but the error is something else, I already tried to find any specific example for the pagination in the functional version but don't have any luck.
Could be great if somebody can help me to understand how to fix this Property type not supported message, or understand if is not possible to use the pagination with the Functional version.

Подробнее здесь: https://stackoverflow.com/questions/794 ... ion-not-cl
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»