php 添加数据无法添加,关于php:无法使用laravel从请求中添加数据

我有这个功能:

public function store(Requests\OfferRequest $request)

{

$offer = new Offer($request->all());

Auth::user()->offer()->save($offer);

$maxoffer =  Maxoffer::where('article_id', $request->input('article_id'))

->where('start', $request->input('start'))->get();

if($maxoffer == null)

{

Auth::user()->maxoffer()->create($request->all());

}

else

{

if($maxoffer->price < $request->input('price'))

{

$newOffer = Auth::user()->maxoffer()

->where('id', $maxoffer->id)

->update(['price'=>$request->input('price')]);

}

}

Alert::success('Offer is succesfully added!', 'Good job!')->persistent("Close");

return Redirect::back();

}

但是我无法添加数据,因为我得到了以下信息:

ErrorException in OffersController.php line 63: Undefined property:

Illuminate\Database\Eloquent\Collection::$price in

OffersController.php line 63 at HandleExceptions->handleError('8',

'Undefined property: Illuminate\Database\Eloquent\Collection::$price',

'C:\wamp\www\bidbook\app\Http\Controllers\OffersController.php', '63',

array('request' => object(OfferRequest), 'offer' => object(Offer),

'maxoffer' => object(Collection))) in OffersController.php line 63

这里有什么问题?

什么结果dd($ maxoffer)?

null .......................但是为什么,这是怎么回事:$ maxoffer = Maxoffer :: where(article_id,$ request-> input(article_id) )-> where(start,$ request-> input(start))-> get();

什么是dd($ request-> all());

数组:5 [▼" _token" =>" c8RwNaQY1smgPAMDmjCx8VP396RjemnVOoewHaqb"" article_id" =>" 1""键" =>" On6IH0PBQRewsOukcZkcdzsriqid5R""开始" =>" 02/16/2016 12:00"" 61.00"]

以下返回一个集合:

$maxoffer =  Maxoffer::where('article_id', $request->input('article_id'))

->where('start', $request->input('start'))

->get(); // Returns a collection

所以你得到了错误。 只需将get更改为first例如:

$maxoffer =  Maxoffer::where('article_id', $request->input('article_id'))

->where('start', $request->input('start'))

->first(); // Returns a single Eloquent Object

现在,这将返回单个Eloquent Model对象,并且在找到任何模型的情况下将起作用。

问题是因为我的$ request-> input(start)是2016-02-02 12:00 am,而从数据库开始是2016-02-02 00:00:00 ...如何解决此问题? 要用碳$ request-> input(start)转换?

您对该字段的数据类型是什么,希望它带有时间戳。

我也尝试使input(start)= 2016-02-02 00:00:00但又一次不起作用,只返回结果为NULL

尝试这个

$maxoffer =  Maxoffer::where('article_id', $request->['article_id'])

->where('start', $request->['start'])->get();

嗯,不,那是相同的,但是然后我得到的不是数组,而是集合-在ControllerController.php第54行中出现FatalErrorException:语法错误,意外[,期望标识符(T_STRING)或变量(T_VARIABLE)或{或$

这个答案并不能解释您的想法是什么错,以及您的更改将如何解决它。 此外,它还会引入语法错误,这绝对不能解决该问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值