将函数中的变量传递给laravel中的请求

时间:2016-02-18 22:05:34

标签: controller request laravel-5.1

你好我有一个问题试图了解laravel,我试图将数据从一个函数传递到请求保存在数据库中,我不断收到此错误:尝试分配非对象的属性

public function active()
{
    $activity = str_random(25);

    $result = purchase::where('active', '=', $activity)->get()->first();
    if(!$result){

        return $activity;
    }
}

public function store(AddOrder $request)
{
    $user = new Bid();
    $user = $request->all();
    $user->activate = $this->active();

    return $user;
}

非常感谢

1 个答案:

答案 0 :(得分:0)

很抱歉找到了

已更改

public function store(AddOrder $request)
{
$user = new Bid();
$user = $request->all();
$user->activate = $this->active();

return $user;
}

public function store(AddOrder $request)
{
$user = new Bid();
$user = $request->all();
$user['activate'] = $this->active();

return $user;
}