Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
laravel angularjs更新多行_Angularjs_Laravel - Fatal编程技术网

laravel angularjs更新多行

laravel angularjs更新多行,angularjs,laravel,Angularjs,Laravel,我有一个可排序的表,在成功移动一个项目后,我想更新数据库表中受排序影响的所有行 我的问题是,我不知道用eloquent更新数据库中多行的最佳方法是什么,以及如何用angularjs正确发送数据 在angularjs,我这样做了 //creating the array which i want to send to the server var update = []; for (min; min <= max; min++){ ... var item = {"id":

我有一个可排序的表,在成功移动一个项目后,我想更新数据库表中受排序影响的所有行

我的问题是,我不知道用eloquent更新数据库中多行的最佳方法是什么,以及如何用angularjs正确发送数据

在angularjs,我这样做了

//creating the array which i want to send to the server
var update = [];
for (min; min <= max; min++){
    ...
    var item = {"id": id, "position": position};    
    update.push(item);
    ...
}
//it doesn't work because its now a string ...
var promise = $http.put("/api/album/category/"+update);

//yeah i can read update in my controller in laraval, but i need the fakeid, because without 
//i get an error back from laravel...  
var promise = $http.put("/api/album/category/fakeid", update); 
试着用post代替put。 var promise=$http.post(“/api/album/category/fakeid”,update)

PUT意味着放置一个资源——用一个不同的东西完全替换给定URL上可用的任何东西。根据定义,PUT是幂等的。你想做多少次就做多少次,结果都一样。x=5是幂等的。您可以放置资源,无论它以前是否存在(例如,创建或更新)

POST更新资源、添加辅助资源或引起更改。POST不是幂等的,就像x++不是幂等的一样

通过这个参数,PUT用于在您知道要创建的对象的URL时创建。当您知道要创建的类别的“工厂”或经理的URL时,可以使用POST来创建

因此:

员额/费用报告 或:

出售/费用报告/10929

我是通过以下方式学习的

拉维+角度+自举

拉维+角度+材质

希望这有助于您了解如何利用引导和角度,并通过使用starter加速您的开发。您将能够理解如何将API请求传递给laravel并获得回调响应

//my route
Route::resource('/api/album/category','CategoryController');

//controller
class CategoryController extends BaseController {
    public function update()
    {
        $updates = Input::all();

        for($i = 0; $i<count($updates); $i++){
            Category::where('id','=', $updates[$i]["id"])
            ->update(array('position' =>  $updates[$i]["position"]));
        }
    }
}
//angularjs
var promise = $http.put("/api/album/category/positionUpdate", update);
//laravel
Route::put('/api/album/category/positionUpdate','CategoryController@positionUpdate');