rully
1 week ago

how to auto add users_id in foreign key and one to many relations

Posted 1 week ago by rully

this the controller

`public function store(Request $request) { $siswa = new Siswa; $siswa->nama = $request->nama; $siswa->nisn = $request->nisn; $siswa->pict = $request->pict; $siswa->kelas = $request->kelas; $siswa->jurusan = $request->jurusan; $siswa->save();

    toastr('success!');
    return back();
}`

this is the siswa model

public function user() { return $this->hasMany(User::class); }

this is the users model

public function Siswa() { return $this->belongsTo(Siswa::class); }

Please sign in or create an account to participate in this conversation.