Php 传递给::set的参数1必须是App\date的实例,字符串为
在我的模型中Php 传递给::set的参数1必须是App\date的实例,字符串为,php,laravel,date,Php,Laravel,Date,在我的模型中 public function setReceptionDate(date $reception_date) { $this->reception_date=$reception_date->date('Y-m-d'); } public function getReceptionDate(): date { return $this->Reception_date; } 在我的控制器中 $machine->setRecep
public function setReceptionDate(date $reception_date)
{
$this->reception_date=$reception_date->date('Y-m-d');
}
public function getReceptionDate(): date
{
return $this->Reception_date;
}
在我的控制器中
$machine->setReceptionDate($reception_date);
在my blade.php中
<label for="date" class="date-style">
<span id="dateFecha">Fecha de Recepción</span>
<input type="date" name="receptionDate" class="date-input-style" />
雷杰普西翁酒店
我不知道错误在哪里,如果您使用的是Laravel 6.x或更高版本,请提供帮助,然后您可以强制转换接收日期属性
protected$casts=[
“接收日期”=>“日期时间:Y-m-d”,
];
不需要访问器和变异器函数:getReceptionDate
&setReceptionDate
在控制器中,您可以直接为属性分配有效的字符串文字
$receptionDate=“2020-10-01”;
$machine->receipt\u date=$receiptondate;
Laravel文档:如果我正确理解您的控制器使用情况
public function setReceptionDate(date $reception_date)
{
$this->reception_date=$reception_date->date('Y-m-d');
}
正在从窗体接收字符串。然而你却把它当作一门约会课
尝试首先将其转换为日期类,或者直接按原样保存,而不使用->日期函数(就像您正在尝试的那样)类型为
date
的输入将提交一个字符串(就像错误提示的那样)。