這是我的模特class Gallery extends Model{ protected $table = 'gallery';protected $fillable = [ 'id','pages_id','title','subtitle'];protected $casts =[ 'photo'=>'array'];}這是控制器public function add_gallery(Request $request, $id){ $gal = Gallery::create([ 'title' => $request['titlu'], 'subtitle' => $request['autor'], 'photo' => json_encode($p), 'pages_id' => $id ]);}'photo' => json_encode($p) 行不起作用,它表示 photo 列為空,$p 不為空
1 回答

慕桂英4014372
TA貢獻(xiàn)1871條經(jīng)驗 獲得超13個贊
$photo 應(yīng)該添加到 $fillable
protected $fillable = ['id','pages_id','title','subtitle','photo'];
由于您確實使用了轉(zhuǎn)換,因此您無需手動使用 json_encode/json_decode,因為 Laravel 正在為您執(zhí)行此操作。
$gal = Gallery::create([
'title' => $request['titlu'],
'subtitle' => $request['autor'],
'photo' => $p,
'pages_id' => $id
]);
$p 變量不存在于 add_gallery() 方法中。
- 1 回答
- 0 關(guān)注
- 238 瀏覽
添加回答
舉報
0/150
提交
取消