1 year ago

How to assign field from another model?

Posted 1 year ago by fikri1510

I have Model Profile and Participant, they are related by ssn. I want to save Participant to database from ParticipantController where one field is coming from Profile model(which is ssn).

public function store(Request $request){
    $participant = new Participant;
    $profile = new Profile;   
    $participant->ssn = $profile->ssn; //can I just do like this?
    return view('after_registration');

or do i need to write query to retrieve ssn from profile and later assign it to participant field?

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