gpt4 book ai didi

php - Laravel:字段不插入

转载 作者:行者123 更新时间:2023-12-05 08:12:59 25 4
gpt4 key购买 nike

我有四个字段没有被插入到我的产品表中,我已经检查了这些字段是否有值但它们没有被插入并且这些字段由一个选择框填充,除了 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_idcategory_idbrand_idcreated_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');
}
}

最佳答案

在“保存产品”部分,要实际保存产品,您必须调用:$产品->保存();

编辑- 事实上你不需要。不确定我是应该删除它还是把它留在这里。

关于php - Laravel:字段不插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36995075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com