duanque3125 2014-01-25 09:12
浏览 60
已采纳

too long

When using the $guarded property on Laravel models is it best practice to always include any relation foreign keys, so they cannot be mass assigned using $model::create($data); syntax?

e.g. i currently often do the following:

class Application extends Eloquent {

    protected $guarded = array('id','job_id','organisation_id','user_id');

        ...
  • 写回答

1条回答 默认 最新

  • duanping3587 2014-01-25 20:48
    关注

    I think it's best practice just as much as it is for the model's primary key, since the goal is to prevent attacks when passing HTTP request input data into the model without checking if it contains "illegal" keys (which is what is done most of the time with mass assignment). Even with CSRF token and all possible precautions, ultimately better not trust the HTTP request input data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?