Сохранение отношения один ко многим в базу данных с использованием laravel + vuetify. js - PullRequest
0 голосов
/ 16 апреля 2020

мои миграции:

    Schema::create('departments', function (Blueprint $table) {
        $table->increments('id');
        $table->string('Name_En');
        $table->string('Name_Ku');
        $table->string('Name_Ar');
        $table->integer('faculty_id')->unsigned();
        $table->foreign('faculty_id')->references('id')->on('faculties');
        $table->timestamps();
    });
    Schema::create('faculties', function (Blueprint $table) {
        $table->increments('id');
        $table->string('Name_En');
        $table->string('Name_Ar');
        $table->string('Name_Ku');
        $table->timestamps();
    });
 **models**:

      public function departments()
         {
          return $this->hasMany("App\Department");
         }
       public function faculty()
{
    return $this->belongsTo('App\Faculty');
}
**[

[метод] [1]

] [2] **: publi c хранилище функций (Запрос $ request) {$ request-> validate (['Name_En' => 'required', 'Name_Ku' => 'required', 'Name_Ar' => 'required',

    ]);
    Department::create([
        'Name_En'=>$request->Name_En,
        'Name_Ku'=>$request->Name_Ku,

        'Name_Ar'=>$request->Name_Ar,
        'faculty_id'=>$request->faculty_id
    ]);



}
...