Update
UserController
<?php
...
use App\User;
class UserController extends Controller
{
public function store(Request $request)
{
try {
$this->validate($request, User::STORE_RULES);
DB::beginTransaction();
$input = $request->all();
$user = User::create($input);
DB::commit();
return Response::json([
'code' => 200,
'message' => 'OK',
'url' => url("/api/v1/users"),
'data' => User::whereId($user->id)->first(),
]);
} catch (ValidationException $e) {
return Response::json([
'code' => 400,
'message' => $e->getMessage(),
'url' => url("/api/v1/users"),
'data' => $e->validator->errors()->all(),
]);
} catch (QueryException $e) {
DB::rollback();
return Response::json([
'code' => 500,
'message' => 'KO',
'url' => url("/api/v1/users"),
'data' => [],
]);
}
}
...
UserTableSeeder
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
public function run()
{
factory(App\User::class, 1)->create()->each(function ($user) {
$user->name = 'username';
$user->phone = '666 666 666';
$user->email = '[email protected]';
$user->password = bcrypt('root');
$user->role_id = App\Role::whereName('admin')->first()->id;
$user->save();
});
factory(App\User::class, 19)->create();
}
}
Proceso
composer install
php artisan key:generate
php artisan migrate
php artisan passport:client --password
php artisan passport:keys
php artisan config:cache
php artisan db:seed