Javascript Vue.js和Laravel差异返回json和资源
我对两者的区别感到困惑。看起来它们提供了相同的功能。下面是每个控制器的外观示例 返回json控制器Javascript Vue.js和Laravel差异返回json和资源,javascript,laravel,vue.js,Javascript,Laravel,Vue.js,我对两者的区别感到困惑。看起来它们提供了相同的功能。下面是每个控制器的外观示例 返回json控制器 public function index() { $department = Department::orderBy('created_at', 'desc')->get(); return response()->json($department); } public function index() { $department = Departm
public function index() {
$department = Department::orderBy('created_at', 'desc')->get();
return response()->json($department);
}
public function index() {
$department = Department::orderBy('created_at', 'desc')->get();
return DepartmentResource::collection($department);
}
返回资源控制器
public function index() {
$department = Department::orderBy('created_at', 'desc')->get();
return response()->json($department);
}
public function index() {
$department = Department::orderBy('created_at', 'desc')->get();
return DepartmentResource::collection($department);
}
不同之处在于,第一种方法会将model方法触发到array