1
I am creating an API using Lumen v5.8, and before saving the data in the database I am validating data from an array sent by the user but the data never pass the validation.
Controller
<?php
namespace App\Http\Controllers;
use App\Lista;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ListaController extends Controller{
public function index(){
return response(Lista::all());
}
public function store(Request $request){
$this->validate($request, [
'nome' => 'required|max:20'
]);// o código não passa daqui
$request = $request->json()->all();
$lista = new Lista();
$lista->nome = $request['nome'];
try{
$lista->save();
return response(['201']);
}
catch(Exception $e) {
return response(['400']);
}
}
public function update(Request $request, $id){
}
public function delet($id){
}
}
Route
<?php
use Illuminate\Http\Request;
$router->group(['prefix' => 'listas'], function () use ($router) {
$router->get('/','ListaController@index');
$router->post('/','ListaController@store');
$router->put('/','ListaController@update');
$router->delete('/','ListaController@delete');
});