Ir para conteúdo

Chris Martin

Members
  • Total de itens

    136
  • Registro em

  • Última visita

Tudo que Chris Martin postou

  1. Chris Martin

    Relacionamentos Laravel

    Pessoal, estou com um problema com relacionamentos no laravel. (Inclusive pode ser até falta de atenção minha), mas quebrei a cabeça demais e não consegui; Tenho as tabelas 'arquiteto' e 'cliente' e um arquiteto tem vários clientes, só que não consegui fazer o relacionamento aparecer na tabela 'cliente' tenho o campo `arquiteto_id' que referencia o 'id' da tabela 'arquitetos', só que quando fiz a relação na model Arquiteto ela não está aparecendo class Arquiteto extends Model{ protected $fillable = [...]; public function clientes() { return $this->hasMany('App\Cliente'); } }
  2. Chris Martin

    Relacionamentos Laravel

    Quando eu entro no phpmyadmin, os relacionamentos estão funcionando, mas por algum motivo o laravel não está reconhecendo
  3. Chris Martin

    Relacionamentos Laravel

    Mesmo assim continua retornando nulo olha a migration clientes Schema::create('clientes', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->string("telefone"); $table->string("email"); $table->string('logradouro'); $table->string('cidade'); $table->string('uf'); $table->string('bairro'); $table->string('numero'); $table->string('complemento')->nullable(); $table->bigInteger('arquiteto_id')->unsigned(); $table->timestamps(); $table->softDeletes(); $table->foreign('arquiteto_id')->references('id')->on('arquitetos'); }); }
  4. Chris Martin

    Erro de migração no laravel

    Pessoal, estou com um problema para criar uma foreign com as migrations do laravel. SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `users` add constraint `users_equipe_id_foreign` foreign key (`equipe_id`) references `equipe` (`id`)) at /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) { > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace: 1 PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint") /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458 2 PDOStatement::execute() /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458 Create Users seed public function up() { Schema::dropIfExists('users'); Schema::enableForeignKeyConstraints(); Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id')->index(); //Informações do atleta $table->string('name'); $table->string('tel')->nullable(); $table->string('nacionalidade',2)->nullable(); $table->string('cpf', 11)->unique(); $table->date('data_nascimento')->nullable(); $table->char('genero', 1); //Informações de login $table->string('email')->unique(); $table->string('avatar')->nullable()->default('user_defatult.png'); $table->string('password'); $table->string('status')->nullable()->default(1); $table->string('permission')->nullable()->default('app.atleta'); $table->timestamp('email_verified_at')->nullable(); $table->rememberToken(); //Demais informações $table->string('cep')->nullable(); $table->string('logradouro')->nullable(); $table->string('bairro')->nullable(); $table->string('cidade')->nullable(); $table->string('uf')->nullable(); $table->string('complemento')->nullable(); $table->string('emer_nome')->nullable(); $table->string('emer_tel')->nullable(); $table->integer('equipe_id')->unsigned(); $table->timestamps(); }); } Create Tables Equipe: public function up() { Schema::dropIfExists('equipes'); Schema::create('equipes', function (Blueprint $table) { $table->bigIncrements('id')->index(); $table->string('nome'); $table->integer('status'); $table->timestamps(); }); } Alter Table Users public function up() { Schema::table('users', function (Blueprint $table) { $table->foreign('equipe_id')->references('id')->on('equipe'); }); } a migration é executada nesta ordem, mas o errro persiste
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.