Php 做这件事的最好方法是使用资源和有说服力的laravel 4
做这件事的任何最好的方法都将不胜感激 这样做的目的是从表单中获取输入并将其保存到数据库中Php 做这件事的最好方法是使用资源和有说服力的laravel 4,php,laravel,laravel-4,Php,Laravel,Laravel 4,做这件事的任何最好的方法都将不胜感激 这样做的目的是从表单中获取输入并将其保存到数据库中 public function update() { $file = Input::file('path'); $destinationPath = 'img/'; $filename = $file->getClientOriginalName(); // $extension =$file->getClientOriginalExtension(); $upload_succe
public function update()
{
$file = Input::file('path');
$destinationPath = 'img/';
$filename = $file->getClientOriginalName();
// $extension =$file->getClientOriginalExtension();
$upload_success = Input::file('path')->move($destinationPath, $filename);
$photo = Photo::find($_POST['id']);
$photo->caption = $_POST['caption'];
$photo->path = $destinationPath . $filename;
$photo->save();
if( $upload_success ) {
return Redirect::to('photos/'.$_POST['id'].'/edit')->withInput()->with('success', 'Photo have been updated.');
} else {
return Response::json('error', 400);
}
}
这项工作很好,但我想知道是否有一种简单的方法可以做到这一点,比如如何从表单send to update获取post数据来更新照片信息,而不是使用$\u post并从表单解析中获取id到更新($id)等。谢谢您可以使用输入类,而不是直接访问帖子 我可能会像这样重新编写函数:
public function update()
{
$file = Input::file('path');
$destinationPath = 'img/';
$filename = $file->getClientOriginalName();
if( Input::file('path')->move($destinationPath, $filename) )
{
$photo = Photo::find(Input::get('id'));
$photo->caption = Input::get('caption');
$photo->path = $destinationPath . $filename;
$photo->save();
return Redirect::to('photos/'.$_POST['id'].'/edit')->withInput()->with('success', 'Photo have been updated.');
}
else
{
return Response::json('error', 400);
}
}
另一种选择是直接将这些数据提取到照片模型中,并在其中进行操作。在编写代码之前,您是否可以将这些数据编辑到问题的主体中,以了解其实际用途?谢谢您,巴德,我仍在进行大量学习,我更喜欢拉瓦洛:D