I'm learning how to build an API using Laravel 5.4. *.
No Api.php
:
$this->get('products', 'API\ProductController@index', ['except' => [
'create', 'edit'
]]);
No Product.php
:
class Product extends Model
{
protected $fillable = ['name', 'description'];
}
No ProductController.php
:
private $product;
public function __construct(Product $product)
{
$this->product = $product;
}
public function index()
{
$products = $this->product->all();
return response()->json(['data' => $products]);
}
public function store(Request $request)
{
return response()->json([
'result' => $this->product->create($request->all())
]);
}
I reviewed my code and could not find any errors.
When I use GET it returns the products registered, however when I use POST I get this error:
What can it be?