laraver模型增删改查
增
$UserMessage = new UserMessage;
$UserMessage->user_id = $request->input('user_id'); // 租户id
$UserMessage->title = '秒杀活动已开始'; // 消息标题
$UserMessage->content = '您预约的秒杀-'.$goods['title'].'-商品活动已经开始!' ; //消息内容
$UserMessage->status = '0' ;
$UserMessage->types = '1' ;
$UserMessage->created_at = $time['data']; // 开启时间
$UserMessage->updated_at = $time['data']; // 修改时间
$is = $UserMessage->save();
// $UserMessage->id 添加这条数据返回id
if($is){
$api = [
'code'=>'1',
'msgid'=>$UserMessage->id,//这条数据返回id
'msg'=>'开启成功',
];
return $this->success($api);
}else{
$api = [
'code'=>'0',
'msg'=>'开启失败',
];
return $this->fail($api);
}
删除
两个都可以
$deleted = UserMessage::destroy($request->input('msgid'));
$deleted = UserMessage::where('id',$request->input('msgid'))->delete();
改和添加一样
$UserMessage = new UserMessage;
$UserMessage->id = $request->input('id'); // 数据表id
$UserMessage->user_id = $request->input('user_id'); // 租户id
$UserMessage->title = '秒杀活动已开始'; // 消息标题
$UserMessage->content = '您预约的秒杀-'.$goods['title'].'-商品活动已经开始!' ; //消息内容
$UserMessage->status = '0' ;
$UserMessage->types = '1' ;
$UserMessage->created_at = $time['data']; // 开启时间
$UserMessage->updated_at = $time['data']; // 修改时间
$is = $UserMessage->save();
查
$list = Seckilltime::get(['id','data'])->toArray();
$list = ShopGood::where('id',$request->input('id'))->get()->toArray();
标签:UserMessage,title,request,改查,增删,input,data,id,laraver
From: https://www.cnblogs.com/79524795-Tian/p/16768820.html