Hi, team
I tried to create my own deleteRecord()
function. I have added it to my Resource file but It looks like it is not executed at all. It does not have any code to delete records now but the records is still deleted (I commented it for the testing )... magic...
So what am I doing wrong?
My Resource code (a part):
<?php
namespace...\Special\WineReport\Admin\Resources;
use ...\DB\Database;
use koolreport\dashboard\admin\actions\DeleteAction;
use koolreport\dashboard\admin\actions\DetailAction;
use koolreport\dashboard\admin\actions\InlineEditAction;
use koolreport\dashboard\admin\actions\UpdateAction;
use koolreport\dashboard\admin\relations\HasMany;
use \koolreport\dashboard\admin\Resource;
use \koolreport\dashboard\fields\ID;
use \koolreport\dashboard\fields\Text;
class WineCategory extends Resource
{
protected function onCreated()
{
$this->manageTable('wine_categories')->inSource(Database::class);
}
protected function actions()
{
return [
DetailAction::create(),
UpdateAction::create(),
DeleteAction::create()->enabled(function () {
//Only allow delete if user is admin
return $this->app()->user()->hasRole('admin');
}),
];
}
protected function fields()
{
return [
ID::create('category_id')
->label('id')
->sortable(true)
->showOnUpdate(false)
->showOnCreate(false),
Text::create('category_name'),
];
}
public function deleteRecord($ids)
{
$idColName = $this->getIDField()->colName();
if ($idColName === null) {
throw new \Exception('ID field is required');
}
// $query = $this->getQuery()->whereIn($idColName, $ids)->delete();
// if ($query->run() === false) {
// throw new \Exception('[SQL Error] ' . $query->errorMessage() . ' : ' . $query);
// }
return true;
}
}