Source: sebastiandedeyne.com

Laravel Blade & View Models
A view model represents data for a specific view or page. In its simplest form, a view model is a plain PHP object with a bunch of (typed) properties.

class ProfileController { public function edit() { $viewModel = new ProfileViewModel( user: Auth::user(), companies: Companies::all(), action: action([ProfileController::class, 'update']), ); return view('profile.edit', ['view' => $viewModel]); }} action }}" method="POST"> user->name)}}"> @foreach($view->companies as $company) …

Refactor rename ProfileViewModel in PhpStorm: class ProfileViewModel { public function __construct( public User $user, - public array $companies, + public array $organizations, public string $action, ) {}}

class ProfileViewModel extends ViewModel { public function __construct( public string $name, public string $email, public int $jobId, public array $jobs, public string $storeUrl, ) {}}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners