2 years ago

How to get data from a table which does not have relationship with the other one.

Posted 2 years ago by agilasadi

Ok so, I have a comments table where I store user_id and it is related with the user table, I can get anything from there but than there is userprofile table which has nothing to do with user table, but I want to user user_id from comments table to access userprofile table id, I don't know how to define the foreginkey and stuff in the relationship. my comments table looks like:


and userprofil looks like:

      $table->string('nameSurname')->default('Not Added');

and I'm guessing I need a relationship in comments which look like something:

public function userprofil()
    return $this->hasOne('App\Userprofile');

but somehow I need to use user_id from comments as id in userprofile table.

Sry fro messy look, it is my first time I'm asking a question in laracasts

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