Mysql Larvel雄辩模型保存功能不是保存,而是错误
我目前的问题是,我想将一些值保存到数据库中,但没有保存,也没有收到错误 两者都有,Mysql Larvel雄辩模型保存功能不是保存,而是错误,mysql,laravel,laravel-5,eloquent,Mysql,Laravel,Laravel 5,Eloquent,我目前的问题是,我想将一些值保存到数据库中,但没有保存,也没有收到错误 两者都有,$product-save()或$product update(数组(…)不起作用,我无法解释原因。。我的ASIN模型看起来不错,并且填充了正确的可填充属性 你们知道为什么它不起作用吗 My Laravel版本:Laravel Framework 5.5.36 这是我目前的课程: namespace App\Console\Commands; use Illuminate\Console\Command; use
$product-save()
或$product update(数组(…)
不起作用,我无法解释原因。。我的ASIN模型看起来不错,并且填充了正确的可填充属性
你们知道为什么它不起作用吗
My 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'
];
}
亲切的问候和感谢 在handle方法中使用此选项
$product = App\ASIN::find(1410);
或者,如果希望保持句柄方法相同,则在模型中导入时使用此选项
use App\ASIN as ASIN;
使用Laravel日志:
if(!$product->save()){
foreach($products->errors() as $error){
Log::info($error);
}
}
希望获得帮助。是否通过验证函数验证数据?可能存在拼写错误,并且可能与表列不匹配。我没有验证数据,列名也不正确。我已在
try catch
块中复制并粘贴了调用save
函数,查看您与数据库的连接是否存在问题或无法正常工作。。。但我确实有一个连接,否则我无法将产品属性打印到控制台!您确定您的命令正在运行吗?尝试在句柄函数的开头添加日志。是的,它正在运行!!还要确保您的连接是正确的,并且您没有将数据写入错误的数据库。您能够检索数据吗$product=ASIN::find(1410);dd(产品);请尝试使用forceSave methodLet us。您的find()方法中的参数是ANSI模型中主键的任何值。检查是否在第一个位置检索模型。它也在检索第一个位置!是的!它有两列!试试这个$product->fill(['field\u 1'=>'value','field\u 2'=>'value']);将列名从“ID”更改为“ID”。您的id列是大写的,或者在模型中定义如下受保护的$primaryKey='id';laravel假设您的主键是“id”