我正在学习laravel。我正在努力Rest API
。我已经controller
使用 curl 发布如下
public function post_index()
{
$cat = Input::json();
$dbCat = new Category();
$dbCat->code = $cat->code;
$dbCat->name = $cat->name;
$dbCat->save();
return $dbCat->toJson();
}
当我尝试使用 curl 发布时,我收到以下错误
Message:
Trying to get property of non-object
Location:
C:\xampp\htdocs\NewBlog\application\controllers\api\category.php on line 22
堆栈跟踪是
#0 C:\xampp\htdocs\NewBlog\laravel\laravel.php(42): Laravel\Error::native(8, 'Trying to get p...', 'C:\xampp\htdocs...', 22)
#1 C:\xampp\htdocs\NewBlog\application\controllers\api\category.php(22): Laravel\{closure}(8, 'Trying to get p...', 'C:\xampp\htdocs...', 22, Array)
#2 [internal function]: Api_Category_Controller->post_index()
#3 C:\xampp\htdocs\NewBlog\laravel\routing\controller.php(325): call_user_func_array(Array, Array)
#4 C:\xampp\htdocs\NewBlog\laravel\routing\controller.php(285): Laravel\Routing\Controller->response('index', Array)
#5 C:\xampp\htdocs\NewBlog\laravel\routing\controller.php(165): Laravel\Routing\Controller->execute('index', Array)
#6 C:\xampp\htdocs\NewBlog\laravel\routing\route.php(153): Laravel\Routing\Controller::call('api.category@in...', Array)
#7 C:\xampp\htdocs\NewBlog\laravel\routing\route.php(124): Laravel\Routing\Route->response()
#8 C:\xampp\htdocs\NewBlog\laravel\laravel.php(167): Laravel\Routing\Route->call()
#9 C:\xampp\htdocs\NewBlog\public\index.php(34): require('C:\xampp\htdocs...')
#10 {main}
我怎样才能解决这个问题?