dqrfdl5708 2017-11-13 00:31
浏览 61
已采纳

无法覆盖Laravel中的Model

In the process of learning Laravel and following along with the video tutorials. During episode 11 @ 18 minutes 30 seconds in here.

  1. The instructor creates a new file Model.php inside the app directory.
  2. The new Model.php now extends Eloquent
  3. Inside the new Model.php he adds protected $guarded = [];
  4. He then extends the Post.php to the new Model.php

This allows him to define all the guarded fields in the new Model.php when doing a mass submission in his form. However when I fo this I still get a mass assignment exception.

If I change the Model.php to Models.php (notice the extra 's') then it works. I'm wondering why I can't have another file name Model.php inside the app directory to extend to?

<?php

namespace App;

use Illuminate\Database\Eloquent\Model as Eloquent;

class Model extends Eloquent
{
    protected $guarded = [];
}
  • 写回答

1条回答 默认 最新

  • duan_2000 2017-11-13 01:04
    关注

    You are going to have to use the App\Model; Instead of the use Illuminate\Database\Eloquent\Model;

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大