如何使用laravel更新数据库中的记录

时间:2016-01-25 19:18:01

标签: php laravel-5

我试图更新数据库中的记录。我试图做几次,但似乎是网址是任何人都可以帮助的问题 这是我的控制器方法:

public function postEditCategory($id,Request $request) {
    $name=$request->input('name');
    DB::table('category')->where('id',$id)->update(['name'=>$name]);
    return redirect('category');
}

这就是我的观点:

<form action="category/Edit-category/{{$cat->id}}" method="POST" enctype="multipart/form-code">
    {!! csrf_field() !!}
    <input type="hidden" name="_method" value="PATCH" />
    <td><input type="text" class="form-control" name="name" value="{{$cat->name}}"></td>
    <td><button class="btn btn-success" type="submit">Update Category</button></td>
</form>

那是我的路线:

Route::group(['middleware' => ['web']], function () {
    // your routes here
    Route::controller("home" , "homeController");
    Route::controller("slideshow" , "slideshowController");
    Route::controller("products" , "productsController");
    Route::controller("category" , "categoryController");
    Route::controller("product_image" , "productImageController");
    Route::controller("product_detail" , "productDetailController");
    Route::controller("team" , "teamController");

        // Authentication routes...
    Route::get('auth/login', 'Auth\AuthController@getLogin');
    Route::post('auth/login', 'Auth\AuthController@postLogin');
    Route::get('auth/logout', 'Auth\AuthController@getLogout');

    // Registration routes...
    Route::get('auth/register', 'Auth\AuthController@getRegister');
    Route::post('auth/register', 'Auth\AuthController@postRegister');
});

0 个答案:

没有答案
相关问题