adMethodCallException:在Jenssegers\Mongodb\Eloquent\Model上



我正试图在mongo-usin‘jensegers/laravel-mongodb’模型的数据库中保存一个文档

这是型号

<?php
namespace App;
use JenssegersMongodbEloquentModel;
class Candidate extends Model
{
public function User(){
return $this->belongsTo(User::class);
}
}

和控制器

<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppCandidate;

class CandidateController extends Controller
{
public function __construct(){
//$this->middleware('jwt');
}

public function create(Request $request){
//var_dump($request->all());
$candidate = new Candidate();
$candidate->name($request['name']);
$candidate->source($request['source']);
$candidate->save();

}

}

我收到这个错误

BadMethodCallException: Call to undefined method AppCandidate::name() in file /home/myuser/myproject/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php on line 50

问题很清楚,但我必须如何添加一种方法来添加模型上的属性

查看文档时,应该使用与Eloquent so相同的方法,而不是

$candidate = new Candidate();
$candidate->name($request['name']);
$candidate->source($request['source']);
$candidate->save();

你可以使用:

$candidate = new Candidate();
$candidate->name = $request->input('name');
$candidate->source = $request->input('source');
$candidate->save();

相关内容

  • 没有找到相关文章

最新更新