Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type hinting for the model objects of Eloquent ORM

I haven't used laravel yet, but watching the tutorials on youtube left me with a question to type hinting, that is really important to me.

Now I have read here

Type Hinting Eloquent Models

and here

Eloquent ORM Code Hinting in PhpStorm

but neither addresses the following problem:

namespace App;
use Illuminate\Database\Eloquent\Model;

    class Movie extends Model {
}

now lets say movie has a name, id, length, author

all those fields are not defined in the class movie, but somehow come automagically from the active record ORM eloquent model if I understood correctly

But let's be honest, I wont remember if it was called author, Author or AuthorName. Or MovieLength, Length or TotalTime

how should i remember all of that for ALL models? is there a way to type hint this in php storm?

i mean the fields from all tables in all models.

EDIT

to make it more clear

i want to type:

$m = App\Movie::find(1);
$m->|

where | is my caret. Now what fields do I have on the class Movie?

like image 772
Toskan Avatar asked Oct 31 '22 01:10

Toskan


1 Answers

Your best bet would be to install the laravel-ide-helper ServiceProvider package in your application

https://github.com/barryvdh/laravel-ide-helper

Seems to have a lot of helpful features for type hinting to the IDE.

like image 168
Rob Fonseca Avatar answered Nov 02 '22 22:11

Rob Fonseca