【发布时间】:2017-03-08 06:22:47
【问题描述】:
我目前正在使用带角度的 laravel 5.3。 我的功能很少,例如添加/编辑/删除帖子 现在我决定有另一个功能,只需单击即可删除所有帖子。
不知何故,我检查了一切是否符合我的服务部分,但之后它似乎并没有传递给我在 laravel 中的控制器。
如果我对 angular 或 laravel 使用了错误的语法,有人可以告诉我吗?
我在 web.php 中有这个
Route::resource('posts', 'PostController');
Route::delete('posts/destroyall', array('as' => 'posts.destroyall', 'uses' => 'PostController@destroyall'));
这在我的 PostController.php 中
public function destroyall() {
Post::truncate();
return response()->json(Post::get());
}
这是我的角度控制器
$scope.destroyAll = function () {
Post.destroyAll()
.success(function () {
// Use the get() created in Post service
// Gets all the posts
Post.get()
.success(function(getData) {
$scope.posts = (getData);
});
})
}
这在我的服务中
destroyAll : function () {
return $http.delete('/posts/destroyall/');
}
有人可以给我一个建议吗?
【问题讨论】:
-
您是否将其存储在数据库中(表数据)?
-
@ShankarShastri 是的,存储在数据库中,所以想清除整个表,这是删除所有数据的最简单方法
-
然后只需向您的 PHP 发出一个路由请求,然后调用截断 SQL 语句并截断数据。
-
@ShankarShastri 所以这就像跳过角度,直接从前到后做?但这不会让页面刷新吗?
-
$scope.posts 是您显示帖子的位置吗?如果是,则只需将 $scope.posts 更新为 null;
标签: javascript php angularjs laravel