diff --git a/README.md b/README.md index b9759a6..e50f01b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,26 @@ Esta é a API do aplicativo Cronos-Develop. ### Referências: ### Recomendações de Estudo: ## Documentação: +### Como criar banco de dados e popular: + +Uma vez que a conexão com o banco de dados estiver configurada, o primeiro comando a ser utilizado é: + +``` +php artisan migrate +``` +Isso irá checar se as tabelas no banco de dados estão criadas, e se não estiverem, são automaticamente feitas de acordo com as migrates. +As migrates podem ser vistas em database/migrations/. + +Depois disso, basta utilizar o seguinte comando: + +``` +php artisan db:seed +``` +Isso ira popular o banco de dados de acordo com as factories em database/factories. + +Nota: +Utilize `php artisan migrate --seed` para fazer os dois comandos ao mesmo tempo + ## Deploy: # Instruções de Execução em Máquina Local: diff --git a/app/Http/Controllers/EmpresaController.php b/app/Http/Controllers/EmpresaController.php new file mode 100644 index 0000000..95e87da --- /dev/null +++ b/app/Http/Controllers/EmpresaController.php @@ -0,0 +1,10 @@ +belongsTo(Usuario::class); + } +} diff --git a/app/Models/Pergunta.php b/app/Models/Pergunta.php new file mode 100644 index 0000000..2e7aaeb --- /dev/null +++ b/app/Models/Pergunta.php @@ -0,0 +1,11 @@ + - */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; - - /** - * The attributes that should be hidden for serialization. - * - * @var array - */ - protected $hidden = [ - 'password', - 'remember_token', - ]; - - /** - * Get the attributes that should be cast. - * - * @return array - */ - protected function casts(): array - { - return [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - ]; - } -} diff --git a/app/Models/Usuario.php b/app/Models/Usuario.php new file mode 100644 index 0000000..65364a6 --- /dev/null +++ b/app/Models/Usuario.php @@ -0,0 +1,20 @@ +hasMany(Empresa::class); + } + + public function FunctionName() : Returntype { + + } +} diff --git a/database/factories/EmpresaFactory.php b/database/factories/EmpresaFactory.php new file mode 100644 index 0000000..e109c30 --- /dev/null +++ b/database/factories/EmpresaFactory.php @@ -0,0 +1,30 @@ + + */ +class EmpresaFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $usr_id = Usuario::all()->random()->id; + return [ + 'usuario_id' => $usr_id, + 'usuario_parceiro_id' => Usuario::all()->except($usr_id)->random()->id, + 'nome_da_empresa' => $this->faker->company(), + 'nicho' => $this->faker->jobTitle(), + 'resumo' => $this->faker->realText($maxNbChars = 200, $indexSize = 2) + ]; + } +} diff --git a/database/factories/PerguntaFactory.php b/database/factories/PerguntaFactory.php new file mode 100644 index 0000000..d546c4c --- /dev/null +++ b/database/factories/PerguntaFactory.php @@ -0,0 +1,23 @@ + + */ +class PerguntaFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php deleted file mode 100644 index 584104c..0000000 --- a/database/factories/UserFactory.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class UserFactory extends Factory -{ - /** - * The current password being used by the factory. - */ - protected static ?string $password; - - /** - * Define the model's default state. - * - * @return array - */ - public function definition(): array - { - return [ - 'name' => fake()->name(), - 'email' => fake()->unique()->safeEmail(), - 'email_verified_at' => now(), - 'password' => static::$password ??= Hash::make('password'), - 'remember_token' => Str::random(10), - ]; - } - - /** - * Indicate that the model's email address should be unverified. - */ - public function unverified(): static - { - return $this->state(fn (array $attributes) => [ - 'email_verified_at' => null, - ]); - } -} diff --git a/database/factories/UsuarioFactory.php b/database/factories/UsuarioFactory.php new file mode 100644 index 0000000..52291ca --- /dev/null +++ b/database/factories/UsuarioFactory.php @@ -0,0 +1,36 @@ + + */ +class UsuarioFactory extends Factory +{ + protected static ?string $password; + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $faker = fake('pt_BR'); + $empresario = $faker->boolean(); + return [ + 'name' => $faker->name(), + 'email' => $faker->unique()->safeEmail(), + 'telefone' => $faker->phoneNumber(), + 'senha' => static::$password ??= Hash::make('password'), + 'endereco' => $faker->address(), + 'cep' => $faker->numerify('######-###'), + 'nascimento' => $faker->date(), + 'empresario' => $empresario, + 'cpf_cnpj' => $empresario ? $faker->cnpj() : $faker->cpf(), + 'nome_da_empresa' => $empresario ? $faker->company() : NULL + ]; + } +} diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php deleted file mode 100644 index 05fb5d9..0000000 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ /dev/null @@ -1,49 +0,0 @@ -id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); - - Schema::create('password_reset_tokens', function (Blueprint $table) { - $table->string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - - Schema::create('sessions', function (Blueprint $table) { - $table->string('id')->primary(); - $table->foreignId('user_id')->nullable()->index(); - $table->string('ip_address', 45)->nullable(); - $table->text('user_agent')->nullable(); - $table->longText('payload'); - $table->integer('last_activity')->index(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('users'); - Schema::dropIfExists('password_reset_tokens'); - Schema::dropIfExists('sessions'); - } -}; diff --git a/database/migrations/2024_04_22_022707_create_usuarios_table.php b/database/migrations/2024_04_22_022707_create_usuarios_table.php new file mode 100644 index 0000000..c8df66f --- /dev/null +++ b/database/migrations/2024_04_22_022707_create_usuarios_table.php @@ -0,0 +1,38 @@ +id(); + // $table->primary("id"); + $table->string('name'); + $table->string('email')->unique(); + $table->string('telefone'); + $table->string('senha'); + $table->string('endereco'); + $table->string('cep'); + $table->date('nascimento'); + $table->boolean('empresario'); + $table->string('cpf_cnpj'); + $table->string('nome_da_empresa')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('usuarios'); + } +}; diff --git a/database/migrations/2024_04_22_023457_create_empresas_table.php b/database/migrations/2024_04_22_023457_create_empresas_table.php new file mode 100644 index 0000000..b10240b --- /dev/null +++ b/database/migrations/2024_04_22_023457_create_empresas_table.php @@ -0,0 +1,34 @@ +id(); + $table->unsignedBigInteger('usuario_id'); + $table->foreign('usuario_id')->references('id')->on('usuarios'); + $table->unsignedBigInteger('usuario_parceiro_id'); + $table->foreign('usuario_parceiro_id')->references('id')->on('usuarios'); + $table->string('nome_da_empresa'); + $table->string('nicho'); + $table->string('resumo'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('empresas'); + } +}; diff --git a/database/migrations/2024_04_22_024318_create_perguntas_table.php b/database/migrations/2024_04_22_024318_create_perguntas_table.php new file mode 100644 index 0000000..a4a4416 --- /dev/null +++ b/database/migrations/2024_04_22_024318_create_perguntas_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('pergunta'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('perguntas'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index d01a0ef..c819f6a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,7 +2,9 @@ namespace Database\Seeders; +use App\Models\Empresa; use App\Models\User; +use App\Models\Usuario; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; @@ -13,11 +15,9 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // User::factory(10)->create(); + //User::factory(10)->create(); + Usuario::factory(10)->create(); + Empresa::factory(10)->create(); - User::factory()->create([ - 'name' => 'Test User', - 'email' => 'test@example.com', - ]); } } diff --git a/html/.htaccess b/public/.htaccess similarity index 100% rename from html/.htaccess rename to public/.htaccess diff --git a/html/favicon.ico b/public/favicon.ico similarity index 100% rename from html/favicon.ico rename to public/favicon.ico diff --git a/html/index.php b/public/index.php similarity index 100% rename from html/index.php rename to public/index.php diff --git a/html/robots.txt b/public/robots.txt similarity index 100% rename from html/robots.txt rename to public/robots.txt