-4
I am importing an Excel spreadsheet and need to convert the date to datetime
for Mysql to accept saving. However, I have tried all the options on mutator
of Laravel and I couldn’t make that conversion.
Code:
Controller:
$import = new ComercialImport
class ComercialImport implements
ToCollection,
WithHeadingRow,
public function collection(Collection $rows)
{
/* acredito que teria que mudar aqui na array pois no model nao esta obedecendo, mas nao tenho ideia de como fazer aqui. */
foreach ($rows as $row) {
$com = Comercial::create([
'vigencia_inicial' => $row ['vigencial_inicial'],
'vigencial' => $row ['vigencia_final'],
Model:
class Comercial extends Model
{
protected $guarded = ['id'];
public $timestamps = false;
protected $dates = ['vigencia_inicial', 'Vigencia_final'];
protected $dateFormat = 'd/m/Y';
Error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value
i solved with protected $Dates . .
– GilCwb