Open phuchung2399 opened 1 year ago
As per document a very limited support is available for form in row action, even linking is not available.
<?php
namespace App\Admin\Extensions;
use Illuminate\Database\Eloquent\Model;
use Encore\Admin\Actions\Interactor\Dialog;
use Encore\Admin\Actions\Interactor\Form;
use Encore\Admin\Actions\RowAction;
class ReplyButton extends RowAction
{
public $name = 'RowEditor';
protected $selector = '.import-post';
/**
* @var Interactor\Interactor
*/
protected $interactor;
/**
* Action constructor.
*/
public function __construct()
{
$this->initInteractor();
}
/**
* @throws \Exception
*/
protected function initInteractor()
{
if ($hasForm = method_exists($this, 'form')) {
$this->interactor = new Form($this);
}
if ($hasDialog = method_exists($this, 'dialog')) {
$this->interactor = new Dialog($this);
}
if ($hasForm && $hasDialog) {
throw new \Exception('Can only define one of the methods in `form` and `dialog`');
}
}
public function handle(Model $model)
{
// \Log::info($this->getKey());
// // 下面的代码获取到上传的文件,然后使用`maatwebsite/excel`等包来处理上传你的文件,保存到数据库
// // $request->file('file');
// $id = $this->getKey();
$model->title = request()->input('title');
$model->save();
return $this->response()->success("导入完成!")->refresh();
}
public function form()
{
// $this->hidden('id')->value($this->getKey());
$this->text('title', __('標題'))->rules('required')->value($this->getRow()->title);
$this->textarea('message', __('內文'))->rules('required')->value($this->getRow()->message);
}
/**
* @return string
*/
public function render()
{
$this->addScript();
$modalId = '';
if ($this->interactor instanceof Form) {
$modalId = $this->interactor->getModalId();
// if ($content = $this->form()) {
// return $this->interactor->addElementAttr($content, $this->selector);
// }
}
return sprintf(
"<a data-_key='%s' href='javascript:void(0);' class='%s' %s>%s</a>",
$this->getKey(),
$this->getElementClass(),
$modalId ? "modal='{$modalId}'" : '',
$this->name()
);
}
}
Description:
Currently, I want to use relationships in RowAction like Form() in Laravel-admin. But now I don't know how.
ex:
Looking forward to everyone's support, thanks.