首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >laravel创建省略/跳过字段

laravel创建省略/跳过字段
EN

Stack Overflow用户
提问于 2014-04-06 16:30:52
回答 1查看 112关注 0票数 0

我试着用laravel播种机播撒几个数据库,但它似乎跳过了一些领域。

我就是这样做的:

代码语言:javascript
复制
Item::create(array(
    'name' => 'Category 2',
    'photo' => 'Description of category 2',
    'order' => 1
    'price' => 2.30
    'category_id' => 1,
));

字段'category_id‘和order不在数据库中设置。

我这样叫播种机

代码语言:javascript
复制
Artisan::call('db:seed',array('--database' => 'tenant_'.$user, '--class' => 'TenantSeeder'));

知道为什么会这样吗?

如果我用标准

代码语言:javascript
复制
$item = new Item;
$item->allfields = "its_value";
$item->save();

它工作得很完美

下面是模型的更新:

代码语言:javascript
复制
<?php
class Item extends Model {

    //============================================================================
    // PARENT VARIABLES
    //============================================================================
    protected $table = "items";

    protected $softDelete = true;

    protected $hidden = ['created_at','updated_at'];
    protected $fillable = ['name','price','description','photo'];   //Items that can be mass assigned
    protected $guarded = array('id');

    protected static $rules = [
        'name'          => 'required|min:3',
        'price'         => '',
        'description'   => '',
    ];

    //============================================================================
    // METHODS
    //============================================================================
    public function getId()         {   return $this->getKey();  }
    public function getName()       {   return $this->name;      }
    public function getPhotoSrc()   {   return $this->photo;     }

    public function item_category(){
        return $this->belongsTo('Items_category');
    }

    public function scopeActive($query)
    {
        return $query->where('active', '=', true);
    }
}

和该计划

代码语言:javascript
复制
Schema::create('items', function(Blueprint $table)
        {
            // auto increment id (primary key)
            $table->increments('id');

            $table->string('name')->default('New Item');
            $table->float('price')->default(0);
            $table->string('photo')->nullable();
            $table->integer('order')->unsigned();
            $table->boolean('active')->default(true);
            $table->string('description')->nullable();

            $table->integer('category_id')->unsigned();
            $table->foreign('category_id')->references('id')->on('items_categories')->onDelete('cascade');

            // created_at, updated_at DATETIME
            $table->timestamps();
            $table->softDeletes(); //It is not really deleted, just marked as deleted
        });

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-08 07:45:17

正如User2094178所说,我在$fillable中没有字段

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22896794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档