sagar001
1 month ago
155
2
Laravel

Call to undefined method App\Article::tags() Error

Posted 1 month ago by sagar001

When i am passing data to this method i am getting "Call to undefined method App\Article::tags()". In my article model there is a method

protected function tags()
{
	return $this->belongsToMany(Tag::class);
}

and in my articleController i have this method

public function store(Request $request)
{
        $validatedAttribute = request()->validate([
            'title'     => 'required',
            'excerpt'   => 'required',
            'body'      => 'required'
        ]);

        $article = new Article($validatedAttribute);
        $article->user_id = 1;
        $article->save();

        $article->tags()->attach(request('tags'));

        return redirect('/article');
}

Anybody just tell me what i am doing wrong here.. Thanks :)

Please sign in or create an account to participate in this conversation.