Laravel store method with problem

Asked

Viewed 230 times

0

I’m trying to implement a POST in this method:

 public function store(Request $request)
    {

       $veiculo = new Veiculo($request->(['marca', 'modelo', 'ano', 'preco']));
       $veiculo->save();
      return $this->respondCreated('The veiculo has been created');

    }

I’m thinking he’s in trouble because he’s returning me a 500 error on Postman

{
    "marca": "Ford",
    "modelo": "Fusio",
    "ano": 2014,
    "preco": 137.985
}

inserir a descrição da imagem aqui

  • 1

    Seems like a mistake when it comes to parsing the data, what’s on line 30 of your VeiculosController.php?

  • he’s saying it’s wrong $vehicle = new vehicle($request->(['brand', 'model', 'year', 'price']); I’ve tried to put it that way, but it’s still giving error: $vehicle = new vehicle($request->all());

1 answer

0

The error he is reporting on line 30 is syntax.

Try using the format below:

$veiculo = new Veiculo();
$veiculo->marca = $request->input("marca");
$veiculo->modelo = $request->input("modelo");
$veiculo->ano = $request->input("ano");
$veiculo->preco = $request->input("preco");
$veiculo->save();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.