猿问

Laravel 雄辩地插入到选择中

我正在尝试 laravel eloquent for sql insert into select query 如下 -


$refId='111';

$newStatus='S2';


INSERT INTO parcel(items, status) SELECT items,'$newStatus' FROM parcel where ref_id ='$refId' LIMIT 1;

此查询使用newStatus变量插入到我的数据库的包裹表中,从数据库中选择所需的某些项目。我需要使用 laravel eloquent 来做到这一点,但找不到任何可靠的方法。


提前致谢。


天涯尽头无女友
浏览 105回答 2
2回答

繁花不似锦

// First Create Model Parcel and FInd Your required row with id// Below code use for selecting data from database. $parcel = Parcel::query()->where('database column name', '=', $parcel_id)->first()// If you want to store data in table use below code.$parcel = new Parcel();$percel->items = $item;$percel->status = $newStatus;$percel->save();

泛舟湖上清波郎朗

// First Create Model Parcel and FInd Your required row with id// Below code use for selecting data from database. $parcel = Parcel::query()->where('database column name', '=', $parcel_id)->first()// If you want to store data in table use below code.$parcel = new Parcel();$percel->items = $item;$percel->status = $newStatus;$percel->save();
随时随地看视频慕课网APP
我要回答