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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners