【发布时间】:2014-07-10 13:21:10
【问题描述】:
对于我的模型(研讨会),我有一个名为“日期”的字段,此输入向用户显示该研讨会的日期。我想通过后端输入多个日期(逗号分隔),并在前端向用户显示最接近当前日期的日期。 在我之前的尝试中,我无法将数组保存到数据库中,因此无法在前端向用户显示这些日期之一。
有没有一种简单的方法来创建我上面提到的这种东西,它容易吗?
我之前拥有的:
public function store()
{
if(Input::hasFile('file'))
{
$file = Input::file('file');
$destinationPath = 'uploads/images/workshops/';
$filename = $file->getClientOriginalName();
$upload_success = $file->move($destinationPath, $filename);
}
$new_workshop = array(
'concept' => Input::get('concept'),
'title' => Input::get('title'),
'body' => Input::get('body'),
'author' => Input::get('author'),
'slug' => Str::slug(Input::get('title')),
'image' => str_replace('\\', '/', $upload_success),
$thedate = array();
foreach(explode(',',Input::get('date')) as $date){
array_push($thedate,$date);
}
'date' => $thedate,
);
$rules = array(
'title' => 'required|min:3|max:255',
'body' => 'required|min:10',
'date' => 'required',
);
$validation = Validator::make($new_workshop, $rules);
if ( $validation->fails() )
{
return Redirect::route('admin.workshops.create')->withErrors($validation)->withInput();
}
$workshop = new Workshop($new_workshop);
$workshop->save();
return Redirect::route('admin.workshops.index');
}
【问题讨论】:
标签: php date laravel frontend backend