In Laravel, it's common to use Eloquent models with static methods like firstOrCreate, whereNull, whereNotNull, etc. These methods are part of the Eloquent query builder and are available through the __callStatic magic method, which allows you to call them statically on your model classes.
However, PHPStorm and other IDEs might not recognize these methods as they are not explicitly defined in your model classes. To help the IDE understand and provide autocompletion for these methods, you can use PHPDoc annotations. This is a common practice to improve the development experience by providing better code insights and autocompletion.
Here's how you can annotate your model classes:
/**
* @method static \Illuminate\Database\Eloquent\Builder|static firstOrCreate(array $attributes, array $values = [])
* @method static \Illuminate\Database\Eloquent\Builder|static whereNull(string $column)
* @method static \Illuminate\Database\Eloquent\Builder|static whereNotNull(string $column)
* @method static \Illuminate\Database\Eloquent\Builder|static whereNotIn(string $column, $values)
* @method static \Illuminate\Database\Eloquent\Builder|static whereIn(string $column, $values)
*/
class YourModel extends \Illuminate\Database\Eloquent\Model
{
// Your model code here
}
These annotations are not required for your code to function correctly, but they are helpful for IDEs to provide better support. It's not unusual to see these annotations in projects where developers want to leverage the full power of their IDE's features. If you find it beneficial, feel free to use them. Otherwise, your code should work without them, as these methods are inherently available through Laravel's Eloquent ORM.