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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端