我已经与Laravel开始了一些项目。 Everthing工作正常,只是没有Firefox。 我总是得到错误消息,碳获得了未知数据。 但在所有其他浏览器中它都有效。
我尝试更改输入字段" data"对于deadline_date in to" text"并再次收到消息。如果我停用" deadline_date"的段落工作。
控制器
public function create(StoreMilestone $request)
{
Milestone::create([
'name' => $request->input('name'),
'deadline_date' => $request->input('deadline'),
'description' => $request->input('description')
]);
return redirect()->back();
}
验证
public function rules()
{
return [
'name' => 'required',
'deadline' => 'required|date',
'description' => 'required'
];
}
模型
<?php
namespace App\Http\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Milestone extends Model
{
use SoftDeletes;
public $timestamps = false;
protected $table = 'fairkatert_milestone';
protected $fillable = [ 'name', 'deadline_date', 'description' ];
protected $dates = [ 'deadline_date' ];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function getTasks()
{
return $this->belongsToMany(
'App\Http\Models\Task',
'fairkatert_task_assign_milestone'
);
}
/**
* @return mixed
*/
public function getCloseTasks()
{
return $this->getTasks()
->where('status', 'close')
->count();
}
/**
* @return mixed
*/
public function getOpenTasks()
{
return $this->getTasks()
->where('status', 'open')
->count();
}
/**
* @return string
*/
public function getMilestoneProgress()
{
$total = $this->getTasks()->count();
$close = $this->getCloseTasks();
if($total === 0)
{
$result = 0;
}
else
{
$result = 100 * $close / $total;
}
return number_format($result, 2, '.', '');
}
/**
* @return mixed
*/
public function getUnorderedTasks()
{
$task = Task::where([
'ordered' => false
])->get();
return $task;
}
}
表格
<form method="post" >
<label>Name</label>
<input type="text" class="form-control input-sm" name="name" value="{{ milestone.name }}" placeholder="Milestone">
<label>Deadline</label>
<input type="date" class="form-control input-sm" name="deadline" value="{{ milestone.deadline_date|date('d.m.Y') }}" placeholder="Datum">
<label>Beschreibung</label>
<textarea id="mytextarea" class="form-control input-sm" name="description" rows="5" placeholder="Beschreibung">{{ milestone.description }}</textarea>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
{% if edit == true %}
<button type="submit" formaction="{{ url('milestone/' ~ milestone.id ~ '/edit') }}" class="btn btn-sm btn-success margin-t-5 p">
<i class="fa fa-floppy-o"></i> Milestone bearbeiten
</button>
{% else %}
<button type="submit" formaction="{{ url('milestone/create') }}" class="btn btn-sm btn-success margin-t-5 p">
<i class="fa fa-floppy-o"></i> Milestone speichern
</button>
{% endif %}
答案 0 :(得分:0)
根据你的链接http://imgur.com/h5d8phO
如果您的日期格式为d-m-Y
,那么
Carbon::createFromFormat('Y-m-d', $date);
不会工作,因为你没有指定正确的格式;你需要
Carbon::createFromFormat('d-m-Y', $date);
您指定为值的日期格式的格式必须与要转换为Carbon对象的日期字符串的实际格式匹配。