Criando script simples para Laravel
Nesta fase criei algumas clases simples para adicionar num projeto Laravel que é uma API para obter os paises de o mundo todo.
A base de dados eu já tinha disponivel num backup salvo no meu computador. Assim que baseado nas colunas da base de dados solicitei para AskCodi o seguinte:
Create script for add in my api laravel project. Considerate the next and but you can add
another recomendations:
Create a new migration class called "countries_table", and the table called "countries",
the "up" method contain the nexts columns:
"id" (is autoincremental big integer),"status" (is a string),"name"(is a string),"iso_2" (is a string), "iso_3" (is a string), "phone_prefix" (is a string),
"currency_name" (is a string), "currency_alpha3" (is a string), "latitude" (is a string),"longitude" (is a string), "capital" (is a string),
"region" (is a string), "subregion" (is a string),"relevancy" (is a integer can be null),
"usage_count" (is a integer can be null),
"created_at" (is a datatime),"updated_at" (is a datatime),"deleted_at" (is a datatime)
the "down" method delete all columns.
Create a new MODEL class, called Country, and declared "table" variable
with the value "countries"
Declarared a array with all colunms of database created in the migration class.
Create a a new controller class called CountryController, create a method called "allCountries"
into the CountryController. The method getCountries, get all countries using the Country class model with the static
method "all", the value returned save in a variable called "countries", and the variable
"countries" is passed in a json return.
Create grouping route with prefix named "api/v1". Into the grouping route, create a route
with HTTP method type GET the name os the route is "all-countries", and the route
used the CountryController with the method allCountries.
Na resposta AskCodi criou as clases:
CreateCountriesTable (migration)
Country (model)
CountryController (controller)
A route tipo GET all-countries
O código gerado usei num Laravel que instalei y depois de ter feito a importação da base de dados consegui rodar o script usando Insomnia.
Resultado de geração de código: com sucesso.
Solicitar criar mais metodos a partir de uma clase model especifica
Create various methos for consuming a API project laravel and create his routes. The method number one consulting countries by the name. The method number two get country by iso_3 code
.The method number 3 by the capital country. Create payload json examples for each method. All methods for get data from the next model:
Solicitei para AskCodi gerar uma explicação do código:
A resposta:
Testes unitarios com artisan
AskCodi gerou um CRUD e outros adicionais para testar o model. Segue fragmento da clase:
O codigo gerado considera os seguientes cenarios:
O resultado do teste unitario foi:
Documentação com AskCodi
Gerou uma documentação do model Country, mas ficou com un formato misturado.
Concluções
Gerar código otima
Gerar testing unitario com artisan da um bom ponto de referencia. Mas é preciso configurar algumas coisas a mais para executar bem os testings.
Gerar documentação foi boa mesmo com o problema de formato.
Ao gerar explicação do codigo foi acertada.
Criar metodos a partir de um model especifico não foi precisa. Mas a criação das rotas tem um bom formato.
Top comments (0)