I have two tables in MySQL where one is referencing another.
The first one is the users
table
The second table is the event
table which contains the creator_id
referencing the id
in the users table. so creator_id
is the foreign key.
Now my problem is how to get the name of each user that owns each column in the event
table using laravel.
I'm clueless about how to do this. And the laravel doc I've read so far is not helping.
This is the model for the event
table.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Auth;
use App\signupModel;
class eventModel extends Model
{
//
public $table = "event";
protected $fillable = ['title', 'description', 'event_flier', 'event_logo', 'org_name', 'org_logo', 'free', 'state', 'city' ];
public function getUser(){
$id = Auth::user()->id;
return users::where('id', $this->id);
}
}
?>
The model for the users is:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class signupModel extends Model
{
//
public $table = "users";
protected $primaryKey = 'id';
protected $fillable = [
'first_name', 'last_name', 'email', 'password', 'gender', 'phoneNumber', 'twitter', 'facebook', 'instagram', 'dob'
];
}
I just want a way where each user can see his data from the event
table when logged in using laravel.
please help. Thanks.