首页 > 代码库 > laravel blog edit

laravel blog edit

模板复制create的模板 主要修改的地方 <form action="{{ url(‘admin/article/‘.$article->id) }}" method="POST"> 以及 {{ method_field(‘PUT‘) }}
PHP文件修改:
public function edit($id)

{

$article = Article::find($id); return view(‘admin/article/edit‘)->with(‘article‘, $article);

}

`public function update($id, Request $request)
{
$this->validate($request, [ // 排除掉当前编辑的数据
‘title‘ => ‘required|unique:articles,title,‘ . $id . ‘|max:255‘,
‘body‘ => ‘required‘,
]);

    $article          = Article::findOrFail($id);
    $article->title   = $request->get(‘title‘);
    $article->body    = $request->get(‘body‘);
    $article->user_id = $request->user()->id;

    if ($article->save()) {
        return redirect(‘admin/article‘);
    } else {
        return redirect()->back()->withInput()->withErrors(‘保存信息失败!‘);
    }
}`

laravel blog edit