Overview:
I have two tables called event_meta
and options
.
Options:
Event Meta:
I have a table called Event Meta where the sub information of specific event are stored. Now what I want to happen is to connect the event_meta
and options
table using leftjoin
in eloquent.
Here's my code for that.
public function getMetaValue($key) {
$event_meta = $this->hasOne('Core\Event\EventMeta', 'event_id')
->leftjoin('options', 'options.id', '=', 'event_meta.meta_value')
->where('meta_key', '=', $key)
->first();
// If Option[table] value is empty, it will retrieve for Event Meta's[table] value, else It will return false.
return (empty($event_meta->value)) ? (empty($event_meta->meta_value)) ? false : $event_meta->meta_value : $event_meta->value;
}
Now the problem is.. If I retrieve the meta_key
logo...
It retrieves the value from options table called Top Up
that has the id of 6
Notice the first character in meta_key
logo's meta_value
it has the same value in option's id.
I tried changing the 6
to 7
, the value's change and it retrieves the Option's Vending POS
.
Any solution for this? This isn't supposed to happen though. Since logo's value is waaay longer than the actual id of options.
--- Edit ---
My attempts fixing it while waiting for help.
1st Attempt:
I tried this solution just for the sake it might be fixed. Still does not work.
public function getMetaValue($key) {
$event_meta = $this->hasOne('Core\Event\EventMeta', 'event_id')
->leftjoin('options', function($query) {
$query->on('options.id', '=', 'event_meta.meta_value');
})->where('meta_key', '=', $key)
->first();
return (empty($event_meta->value)) ? (empty($event_meta->meta_value)) ? false : $event_meta->meta_value : $event_meta->value;
}