我有四个字段未插入到我的产品表中,我检查过这些字段是否有值但是没有插入这些字段,这些字段由created_by
字段以外的选择框填充。
产品表格架构:
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->integer('supplier_id')->unsigned();
$table->integer('category_id')->unsigned();
$table->integer('brand_id')->unsigned();
$table->string('title');
$table->string('slug');
etc....
});
保存产品:
$product = Product::create([
'created_by' => Auth::user()->id,
'supplier_id' => intval($request['supplier_id']),
'category_id' => $request['category_id'],
'brand_id' => $request->get('brand_id'),
'title' => $request->get('title'),
'slug' => str_slug( $request->get('title'), '-' ),
etc...
)};
所有字段在提交时都会保留值,但字段(supplier_id
,category_id
,brand_id
,created_by
)未插入表中 - 它们的值为是字符串
我的模特:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table = "products";
protected $fillable = [
'supplier_id', 'category_id', 'brand_id', 'title', 'slug',
'created_by', 'updated_by'
];
}
use Illuminate\Database\Migrations\Migration;
class CreateTableProducts extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Create table for storing products
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->integer('supplier_id')->unsigned();
$table->integer('category_id')->unsigned();
$table->integer('brand_id')->unsigned();
$table->string('title');
$table->string('slug');
$table->string('keywords', 160);
$table->integer('template_id')->unsigned();
$table->text('video_clip')->nullable();
$table->text('body')->nullable();
$table->boolean('active');
$table->boolean('clearance');
$table->string('sku', 100);
$table->string('quantity');
$table->decimal('unit_price');
$table->decimal('sell_price');
$table->decimal('sale_discount')->nullable();
$table->datetime('sale_start')->nullable();
$table->datetime('sale_end')->nullable();
$table->string('promo_code', 20)->nullable();
$table->double('promo_discount')->nullable();
$table->datetime('promo_start')->nullable();
$table->datetime('promo_end')->nullable();
$table->decimal('default_freight');
$table->decimal('international_freight')->nullable();
$table->decimal('expedited_freight')->nullable();
$table->string('weight');
$table->string('dimensions');
$table->text('measurements')->nullable();
$table->integer('created_by')->unsigned();
$table->integer('updated_by')->unsigned()->nullable();
$table->timestamps();
$table->unique(array('title','slug'));
});
Schema::table('products', function(Blueprint $table) {
$table->foreign('created_by')->references('id')->on('users');
$table->foreign('updated_by')->references('id')->on('users');
$table->foreign('supplier_id')->references('id')->on('suppliers');
$table->foreign('category_id')->references('id')->on('categories');
$table->foreign('brand_id')->references('id')->on('brands');
$table->foreign('template_id')->references('id')->on('templates');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('products');
}
}
答案 0 :(得分:-2)
在“保存产品”位中,要实际保存产品,您必须致电: $产品 - &GT;保存();
编辑 - 确实你不需要。不确定我是应该删除它还是留在这里。