Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel中进行大规模演讲后,为雄辩的模型赋值_Php_Laravel_Laravel 4_Eloquent - Fatal编程技术网

Php 在Laravel中进行大规模演讲后,为雄辩的模型赋值

Php 在Laravel中进行大规模演讲后,为雄辩的模型赋值,php,laravel,laravel-4,eloquent,Php,Laravel,Laravel 4,Eloquent,我有以下代码: public function postCreate($subjectId = null) { if ($subjectId) { $subject = Subject::find($subjectId); $input = Input::all(); $v = Validator::make($input, Product::$rules); if ($v->passes()) {

我有以下代码:

public function postCreate($subjectId = null) {
    if ($subjectId) {
        $subject = Subject::find($subjectId);

        $input = Input::all();

        $v = Validator::make($input, Product::$rules);

        if ($v->passes()) {
            $product = new Product($input);
            $amazon_product = new AmazonProduct($input['amazon_id']);
            $product->price($amazon_product->price());

            $subject->products()->save($product);

            Session::flash('message', 'Produkt erfolgreich gespeichert');
            return Redirect::to('boss/subjects/show/'.$subjectId);
        }
    } else {
        Session::flash('message', 'Innerhalb der POST-Action muss die Gruppen-ID angegeben sein.');
        return Redirect::to('boss/subjects');
    }
}
但我得到了以下错误:

Call to undefined method Illuminate\Database\Query\Builder::price()
我认为问题在于,
$product=新产品($input)

有没有办法在那之后再赋值?
price
的值不在
$product

中。您可以使用以下方法:

$product->price = $amazon_product->price();
而不是:

$product->price($amazon_product->price());

这里,
$product
雄辩的模型
对象,
价格
是该对象的属性,但您将其用作
方法

当然,这是一个多么愚蠢的错误。昨天太晚了:)谢谢!