Laravel 5 Call to undefined method Illuminate\Database\Eloquent\Collection::attach()
<p>I am using laravel 5 with many to many relationship. 
Below is my code.</p>

<p>Article.php</p>

<pre><code>namespace App;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Article extends Model {

protected $fillable = ['title', 'body', 'published_at', 'user_id'];

protected $dates = ['published_at'];

public function setPublishedArAttribute($date)
{
    Carbon::createFromFormat('Y-m-d', $date);
    $this-&gt;attributes['published_at'] = Carbon::parse($date);
}

public function scopePublished($query)
{
    $query-&gt;where('published_at', '&lt;=', Carbon::now());
}

public function scopeUnpublished($query)
{
    $query-&gt;where('published_at', '&gt;', Carbon::now());
}

public function user()
{
    return $this-&gt;belongsTo('App\User');
}

public function tags()
{
    return $this-&gt;belongsToMany('App\Tag');
}

}
</code></pre>

<p>Tag.php</p>

<pre><code>namespace App;

use Illuminate\Database\Eloquent\Model;

class Tag extends Model {

protected $fillable = [
    'name'
];

public function articles()
{
    return $this-&gt;belongsToMany('App\Article');
}

}
</code></pre>

<p>ArticleController.php</p>

<pre><code>namespace App\Http\Controllers;
use App\Article;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Request;
use Carbon\Carbon;
use Auth;

class ArticlesController extends Controller {

public function __construct()
{
    $this-&gt;middleware('auth', ['except', 'index']);
}

public function index()
{
    $articles = Article::latest('published_at')-&gt;published()-&gt;get();
    return view('articles.index', compact('articles'));
}

public function show(Article $article)
{
    return view('articles.show', compact('article'));
}

public function create()
{
    if(Auth::guest()){
        return redirect('articles');
    }
    $tags = \App\Tag::lists('name', 'id');
    return view('articles.create', compact('tags'));
}

public function store(Requests\ArticleRequest $request)
{   
    $article = Auth::user()-&gt;articles()-&gt;create($request-&gt;all());
    $article-&gt;tags-&gt;attach($request-&gt;input('tags'));
    \Session::flash('flash_message', 'Your article has been created!');
    Article::create($request-&gt;all());
    return redirect('articles');
}

public function edit(Article $article)
{
    return view('articles.edit', compact('article'));
}

public function update(Article $article, Requests\ArticleRequest $request)
{       
    $article-&gt;update($request-&gt;all());
    return redirect('articles');
}

}
</code></pre>

<p>When I try to create article and store it in database using store function in ArticleController I get following error.</p>

<p>FatalErrorException in ArticlesController.php line : Call to undefined method Illuminate\Database\Eloquent\Collection::attach()</p>

<p>I have set many to many relationship between articles and tags, also properly added migration.</p>

<p>But when I try to add article using tag I get error.
Let me know what is wrong with my code. Is anything missing in setting relationship.</p>

<p>Also this is migration table file</p>

<pre><code>use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTagsTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('tags', function(Blueprint $table)
    {
        $table-&gt;increments('id');
        $table-&gt;string('name');
        $table-&gt;timestamps();
    });

    Schema::create('article_tag', function(Blueprint $table){
        $table-&gt;increments('id');
        $table-&gt;integer('article_id')-&gt;unsigned()-&gt;index();
        $table-&gt;foreign('article_id')-&gt;references('id')-&gt;on('articles')-&gt;onDelete('cascade');
        $table-&gt;integer('tag_id')-&gt;unsigned()-&gt;index();
        $table-&gt;foreign('tag_id')-&gt;references('id')-&gt;on('tags')-&gt;onDelete('cascade');
        $table-&gt;timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('tags');
    Schema::drop('article_tag');
}

}
</code></pre>

<p>Let me know what should I do to make attach work with many to many relationship</p>