这是我的文章模型
function tags()
{
return $this->belongsToMany('App\Tag')->withTimestamps();
}
这是我的文章模型
function articles()
{
return $this->belongsToMany('App\Article');
}
这是我的文章控制器存储方法
public function store(ArticleRequest $request, Article $article)
{
$article=Auth::user()->articles()->create($request->all());
$article->tags()->attach($request->input('tags'));
return redirect('articles');
}
我遇到此错误
Builder.php第2071行中的BadMethodCallException:调用undefined 方法Illuminate \ Database \ Query \ Builder :: tags()
帮我解决这个问题
答案 0 :(得分:0)
如果我尝试 dd($ articles),我就有了这个
Article {#206 ▼
#fillable: array:3 [▶]
#connection: null
#table: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:7 [▶]
#original: array:7 [▶]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: true
}
路线文件
<?php
Route::get('/', function () {
return view('welcome');
});
Route::resource('articles','articlescontroller');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);