I'm trying to store a data via POST method using Laravel\Lumen with Eloquent. The database I'm using is MySQL.
Heres my CategoriesController.php:
<?php
namespace App\Http\Controllers;
use App\Category;
use Illuminate\Http\Client\Request;
class CategoriesController extends Controller
{
public function index()
{
return Category::all();
}
public function create(Request $request)
{
return response()
->json(
Category::create(['description' => $request->description]),
201
);
}
}
Here's my CategoryModel.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $fillable = ['description'];
public function expense()
{
return $this->belongsTo(Expense::class);
}
}
In my App.php file I've uncommented the lines:
$app->withFacades();
$app->withEloquent();
My Web.php file:
$router->group(['prefix' => 'api'], function ($router){
$router->get('categories', 'CategoriesController@index');
$router->post('categories', 'CategoriesController@create');
});
Via Postman I'm sending the following post request:
{
"description" : "teste"
}
After the request was sented I'm having the 500 HTTP Status Response. The error contains the following StackTrace:
BindingResolutionException HTTP 500 Internal Server Error
in C:\Fontes\PHP\budget-manager\vendor\illuminate\container\Container.php (line 1053)
*/ protected function unresolvablePrimitive(ReflectionParameter $parameter)
{
$message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}";
throw new BindingResolutionException($message);
}