Jimmyt1988
Jimmyt1988

Reputation: 21126

Cast to custom class type in PHP

I am using Laravel.

Due to it being MVC, I am passing a model (an object) of a certain class type into the view.

Of course, inside my view... it has no idea what the controller has pushed out when i'm developing, so I lose my typeahead on my ViewModels...

I tried doing something like this:

(TimesheetViewModel)$Model;

But unfortunately that doesn't work...

What I end up having to do is declare a $Model = new TimesheetViewModel(); just to help me develop the page and then get rid of it at the end. It's dumb... Any good ways of helping out my typeahead?

enter image description here

Upvotes: 0

Views: 441

Answers (1)

Andrii Mishchenko
Andrii Mishchenko

Reputation: 2694

Using PHP doc: At the beginning of the view:

<?php
/* @var $model TimesheetViewModel */
?>

Upvotes: 2

Related Questions