Prompt type for light models
I am trying to write some nice code and some of this type is hinting to make things easier down the line and keep waiting.
This may sound a little far-fetched, but to me it's more of a proof of concept.
I am writing a class to split TSV files into tabs and insert into my model. In my constructor, I asked for:
Illuminate\Database\Eloquent\Model
To which I passed:
new \App\Model()
And finally, the error response:
instance of App\Model given
Clearly I did something wrong, but I don't want to force the use of App \ Model, how can I in principle request an eloquent model?
Edit for more information:
To make it clearer, I am using Laravel 5, models are created with artisan make: model. The constructor looks like this:
function __construct ($resource, Illuminate\Database\Eloquent\Model $model, $skip = 0)
And the model I use (for my movie table):
use Illuminate\Database\Eloquent\Model;
class Movie extends Model {
source to share
In your type hint, the FQCN preface with a backslash:
function __construct ($resource, \Illuminate\Database\Eloquent\Model $model, $skip = 0)
Either this, or add an operator use
to your class:
use Illuminate\Database\Eloquent\Model;
class MyClass {
function __construct ($resource, Model $model, $skip = 0) {
//
}
}
source to share