Laravel insert方法无法插入数据到库(排除fillable设置)入门小弟请求指点
开发环境
- Laravel v8.33.1 (PHP v7.4.3)
- Mysql V8.0.12
class Products extends Model
{
// use HasFactory;
protected $fillable = [
'number',
'title',
'squad_id',
'station_id',
'life',
'critical',
'capacity',
'created_time',
'updated_time',
'squad_id',
'note'
];
// ......
在文档和网络中找到大多是在Model 中设置 $fillable 字段,设置后依然无效
以下是待插入数据(print_r($data))
Array
(
[0] => Array
(
[number] => DZ13241242720
[title] => 右后踏板支架总成
[squad_id] => 0
[station_id] => 0
[life] => 1
[created_time] => 1616900199
[updated_time] => 1616900199
)
[1] => Array
(
[number] => DZ13241440010
[title] => 固定横梁
[squad_id] => 0
[station_id] => 0
[life] => 1
[created_time] => 1616900199
[updated_time] => 1616900199
)
)
使用业务如下
$productInsert = DB::table('products')->insert($data);
dd($productInsert);
控制台打印
数据表如下设置,在执行sql语句是可以插入数据
数据库配置文件如下
[mysql]
default-character-set=utf8mb4
[mysqld]
port=3306
default_authentication_plugin=mysql_native_password
basedir=D:/lancema/....文件路径略.../MySQL8.0.12/
datadir=D:/lancema/....文件路径略.../MySQL8.0.12/data/
character-set-server=utf8mb4
default-storage-engine=InnoDB
max_connections=1000
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
innodb_buffer_pool_size=64M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=120
innodb_log_buffer_size=4M
innodb_log_file_size=256M
interactive_timeout=120
join_buffer_size=2M
key_buffer_size=32M
log-error=D:/lancema/....文件路径略.../MySQL8.0.12/data
log_error_verbosity=1
max_allowed_packet=16M
max_heap_table_size=64M
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=32M
read_buffer_size=512kb
read_rnd_buffer_size=4M
server_id=1
skip-external-locking=on
sort_buffer_size=256kb
table_open_cache=256
thread_cache_size=16
tmp_table_size=64M
wait_timeout=120
[client]
port=3306
default-character-set=utf8mb4
入门小弟请求指点!
推荐文章: