问题描述
这是我在 Action Class 中的代码:
public function fields()
{
return [
Date::make('checkin_date'),Date::make('checkout_date'),Textarea::make('remark'),Text::make('holder_name'),Text::make('holder_surname'),Text::make('clientReference'),];
}
什么我要找的是显示在每个字段的实际数据库值。因此,用户要么选择编辑或保存价值,因为它们。
解决方法
您可以访问动作定义上的请求对象,并使用构造函数将值传递给动作。
class MyDemoAction extends Action
{
use InteractsWithQueue,Queueable;
public function __construct(MyDemoModel $model) {
$this->model = $model;
}
public function handle(ActionFields $fields,Collection $models)
{
//
}
public function fields()
{
return [
Date::make('checkin_date')->default(function() {
$this->model->my_value;
}),Date::make('checkout_date'),Textarea::make('remark'),Text::make('holder_name'),Text::make('holder_surname'),Text::make('clientReference'),];
}
为了确保您始终可以传递有效的 MyModel 对象,您可以将您的操作限制为仅在 resourceDetail 上可见。 Registering A