Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我怎么能在一段拉维关系中多次使用同一型号?_Php_Laravel - Fatal编程技术网

Php 我怎么能在一段拉维关系中多次使用同一型号?

Php 我怎么能在一段拉维关系中多次使用同一型号?,php,laravel,Php,Laravel,我正在开发一个应用程序,在这个程序中,用户可以进行附加培训,并进行一些描述。 因此,他们可以在高中接受培训,并附上“Rockford高中”的描述。然而,我希望他们能够把几次相同的类型,所以他们可以有3个高中,或大学等 但是,当我尝试使用相同id附加两次相同的模型时,其中一个会被覆盖。我认为使用中间模型可以解决这个问题,但事实并非如此 这是我的迁移和任何相关代码 称我为白痴,但我认为这样的话对你的情况来说是有意义的: Schema::create('trainings', function (Bl

我正在开发一个应用程序,在这个程序中,用户可以进行附加培训,并进行一些描述。 因此,他们可以在高中接受培训,并附上“Rockford高中”的描述。然而,我希望他们能够把几次相同的类型,所以他们可以有3个高中,或大学等

但是,当我尝试使用相同id附加两次相同的模型时,其中一个会被覆盖。我认为使用中间模型可以解决这个问题,但事实并非如此

这是我的迁移和任何相关代码


称我为白痴,但我认为这样的话对你的情况来说是有意义的:

Schema::create('trainings', function (Blueprint $table) {
    $table->id();
    $table->string('name_french');
    $table->string('name_english'); 
    // You should checkout 'spatie/laravel-translatable' package, that 
    // way you can use one column for 'name' and then translate it in realtime
    // depending on your application locale.
    $table->timestamps();
});

Schema::create('candidate_practice', function (Blueprint $table) {
   $table->id();
   $table->string('candidate_id');
   $table->string('training_id');
   $table->timestamps(); // Probably not needed
});

Schema::create('practices', function (Blueprint $table) {
   $table->id();
   $table->foreignId('candidate_id')
         ->constrained()
         ->onDelete('cascade');
   $table->string('description');
   $table->timestamps();
});

Schema::create('candidates', function (Blueprint $table) {
    $table->id();
    $table->string('first_name');
    $table->string('last_name');
    $table->string('email');
    $table->string('phone_number');
    $table->string('address');
    $table->string('field_of_work')->default('{}');
    $table->string('formations')->default('{}');
    $table->string('work_experiences')->default('{}');
    $table->string('interests')->default('{}');
    $table->string('cv')->default('');
    $table->string('video_cv')->default('');
    $table->timestamps();
});
现在,您可以通过一对多关系创建与用户相关的多个实践,该关系更易于单独编辑或删除,而无需使用其他资源,然后将实践与培训关联起来


这样,就不再需要创建
CandidatePractice.php
pivot类了。

我们需要查看附加培训的代码?这是可行的:)
Schema::create('trainings', function (Blueprint $table) {
    $table->id();
    $table->string('name_french');
    $table->string('name_english');
    $table->timestamps();
});

Schema::create('candidate_training', function (Blueprint $table) {
    $table->id();
    $table->string('candidate_id');
    $table->string('training_id');
    $table->string('description');
    $table->timestamps();
});

Schema::create('candidates', function (Blueprint $table) {
    $table->id();
    $table->string('first_name');
    $table->string('last_name');
    $table->string('email');
    $table->string('phone_number');
    $table->string('address');
    $table->string('field_of_work')->default('{}');
    $table->string('formations')->default('{}');
    $table->string('work_experiences')->default('{}');
    $table->string('interests')->default('{}');
    $table->string('cv')->default('');
    $table->string('video_cv')->default('');
    $table->timestamps();
});
Schema::create('trainings', function (Blueprint $table) {
    $table->id();
    $table->string('name_french');
    $table->string('name_english'); 
    // You should checkout 'spatie/laravel-translatable' package, that 
    // way you can use one column for 'name' and then translate it in realtime
    // depending on your application locale.
    $table->timestamps();
});

Schema::create('candidate_practice', function (Blueprint $table) {
   $table->id();
   $table->string('candidate_id');
   $table->string('training_id');
   $table->timestamps(); // Probably not needed
});

Schema::create('practices', function (Blueprint $table) {
   $table->id();
   $table->foreignId('candidate_id')
         ->constrained()
         ->onDelete('cascade');
   $table->string('description');
   $table->timestamps();
});

Schema::create('candidates', function (Blueprint $table) {
    $table->id();
    $table->string('first_name');
    $table->string('last_name');
    $table->string('email');
    $table->string('phone_number');
    $table->string('address');
    $table->string('field_of_work')->default('{}');
    $table->string('formations')->default('{}');
    $table->string('work_experiences')->default('{}');
    $table->string('interests')->default('{}');
    $table->string('cv')->default('');
    $table->string('video_cv')->default('');
    $table->timestamps();
});