模型文件
use Illuminate\Database\Eloquent\Model;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Mappable;
class Project extends Model
{
use Eloquence, Mappable;
protected $table = 'projects';
protected $primaryKey = 'id';
protected $maps = [
'projectName' => 'pr_project_name',
'city' => 'pr_city',
];
protected $fillable = ['pr_project_name', 'pr_city'];
}
控制器文件
public function store(Request $request){
$data = $request->all();
$projectData = Project::create($data)->toSql();
return view('project_pages.new_project', compact('projectData'));
}
在数据库中,除了ID和时间戳记之外,所有其他列均插入为null。但是当我执行insert()时,而不是创建,而是出现错误提示
SQLSTATE [42S22]:找不到列:1054未知列
如何使用请求数组中的映射别名将数据插入数据库?