【发布时间】:2018-11-04 13:14:45
【问题描述】:
我目前的问题是我想将一些值保存到数据库中,但没有保存,我也没有收到错误..
$product-save(); 或 $product-update(array(...)) 都不起作用,我不知道为什么。我的 ASIN 模型看起来不错,并且填充了正确的可填充属性...
你们知道为什么它不起作用吗?
我的 Laravel 版本:Laravel Framework 5.5.36
到目前为止,这是我的课:
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\ASIN;
class CheckPrice extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'post:CheckPrice';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$product = ASIN::find(1410);
$product->price = "HELLO";
$product->amountSaved = "HELLO";
$product->percentageSaved = "HELLO";
$product->url = "HELLO";
$product->imgUrl = "HELLO";
$product->save();
//$product->update(array("price" => "HELLO", "amountSaved" => "HELLO", "percentageSaved" => "HELLO", "url" => "HELLO", "imgUrl" => "HELLO"));
$this->printProduct(ASIN::find(1410));
}
到目前为止我的 ASIN 型号: 命名空间应用程序;
use Illuminate\Database\Eloquent\Model;
class ASIN extends Model
{
protected $connection = 'facebook_amazon';
public $table = "ASINS";
protected $fillable = [
'ASIN',
'price',
'amountSaved',
'percentageSaved',
'category',
'url',
'imgUrl',
'showApp'
];
}
诚挚的问候和感谢!
【问题讨论】:
-
您是否通过 validate 函数验证数据?
-
可能有拼写错误,可能与表格列不匹配。
-
我没有验证数据并且列名是正确的。我已经复制并粘贴了它们
-
在
try catch块内调用save函数,看看你的数据库连接是否有问题 -
效果不佳...但我确实有连接,否则我无法将产品属性打印到控制台!
标签: mysql laravel laravel-5 eloquent