doupi1532 2018-05-25 12:10
浏览 135

PhraStorm中模型的Laravel注释

I am creating a project based on Laravel framework and I am using PhpStorm for it. By default, Laravel has the following settings if we enable Laravel plugin in PhpStorm.

PhpStorm Settings

Now based on these settings if I create a model and try to define all the relations and other properties in the following way

<?php
  /**
   * Class User
   *
   * @package App\Http\Entities
   * @property int $id
   * @property mixed $posts
   */
  class User extends Model
  {

      /**
       * The table associated with the model
       *
       * @var string
       */
      protected $table = 'users';

     /**
      * Indicates if model should be timestampped
      *
      * @var bool
      */
      public $timestamps = false;

     /**
      * The attributes are not mass assignable
      *
      * @var array
      */
     protected $guarded = ['type'];

    /**
     * Get all the posts for a user
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function posts()
    {
       return $this->hasMany('App\Http\Entities\Post');
    }

}

Automatically I have to add all the annotations for the class or warning is shown by PhpStorm which is obviously because settings are enabled if I disabled them warnings are gone as well.

But I am curious to know what do they actually represent as it must have some reason if it was set by default. Also when writing other models I noticed that when I defined a function inside a model like this

public function userComments()
{
  return $this->hasMany('Some model');
}

In annotation, it gets set to something like this

/**
 * @property $user_comments
 */

Now firstly it was a function and also for above cases where I defined a function post(), the annotation was set as @property which is again confusing to me. Secondly, I like to define my variable as well as function to camelCase but because of all this annotation getting set at top of the class as snake_case I somehow don't like that.

So all I want to know is what are they basically and what is the purpose of defining them and what do they represent.

P.S. This is my very first project with Laravel framework and I know that it has to do with PHP Documentation and everything but I have never really documented my code earlier. So any suggestion would be helpful.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型
    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题