Closed meandus closed 5 years ago
What is your field definition in the nova resource?
public function fields(Request $request)
{
return [
ID::make()->sortable(),
MorphTo::make(__('Pointable'))->types([
Provider::class,
Client::class,
User::class,
]),
Date::make(__('Date Publishing'))->sortable(),
Date::make(__('Date Value'))->sortable(),
Text::make(__('operation'))
->resolveUsing(function ($name) {
return strtoupper($name);
}),
Number::make(__('debit'))->step(0.01)->sortable(),
Number::make(__('credit'))->step(0.01)->sortable(),
BelongsToMany::make(__('Documents')),
];
}
Try adding ->nullable
to the morphTo field as described in the nova documentation: https://nova.laravel.com/docs/1.0/resources/relationships.html#morphto
I added:
public function fields(Request $request)
{
return [
ID::make()->sortable(),
MorphTo::make(__('Pointable'))->types([
Provider::class,
Client::class,
User::class,
])
->nullable(),
Date::make(__('Date Publishing'))->sortable(),
Date::make(__('Date Value'))->sortable(),
Text::make(__('operation'))
->resolveUsing(function ($name) {
return strtoupper($name);
}),
Number::make(__('debit'))->step(0.01)->sortable(),
Number::make(__('credit'))->step(0.01)->sortable(),
BelongsToMany::make(__('Documents')),
];
}
and now:
The Basic importer implements the WithHeadingRow
interface by default (https://laravel-excel.maatwebsite.nl/3.1/imports/heading-row.html). So you need to access the rows by their header. In your case 'date_publishing' => date("Y-m-d", strtotime($row['Date'])),
return new Statement([
'date_publishing' => date("Y-m-d", strtotime($row['date'])),
'date_value' => date("Y-m-d", strtotime($row['valeur'])),
'operation' => str_replace("\\n", "\\r", $row['libelle']),
'debit' => abs(intval(str_replace($symbols, '', $row['debit']))),
'credit' => abs(intval(str_replace($symbols, '', $row['credit']))),
]);
now it works ! so far so good ! thanks !
Hi,
I would like to extends BasicImporter because i have 2 more fields in my database than in my Excel so i would like to extends BasicImporter and i did that:
But i still have error regarding missing fields (pointable & pointable_type) ... Let me know if you have a good example about Extend BasicImporter .. i don't know which kind of informations you need in attributes or rules or regarding Model
my data in Excel (d/m/Y for date)
my date in database: (Y-m-d for date)
my Migration :
my Model:
Result:
Thanks in advance, Rémy