//controller
$promotion = Promotion::findOrFail($id);
//return
Array
(
[id] => 2
[en_title] => promo1
[game_id] => Array
(
[0] => 3
[1] => 4
[2] => 5
)
[amount] => 100.00
[start_at] => 2021-02-22
[end_at] => 2222-02-22
[status] => 1
)
//model promotion
class Promotion extends Model
{
use HasFactory;
protected $guarded = [];
protected $casts = [
'game_id' => 'array'
];
public function getAllGames()
{
return $this->belongsTo(Game::class, 'game_id', 'id');
}
}问题:
目前,我有两个表,分别是 that 和Pro促进,但是当我陷入关系时会遇到麻烦,因为促进表中的game_id列是JSONE 212,所以很难加入它。是否有任何工作可以轻松地将它们连接在一起,以便检索游戏数据?
发布于 2021-10-30 10:19:40
https://stackoverflow.com/questions/69778587
复制相似问题