title: Call to undefined method : laravel
body: <p>I have simple blog crud app, I have added tags to my pages, am  using <a href="https://select2.org/" rel="nofollow noreferrer">select js</a> for selecting and editing tags in input,</p>
  
  <p>Now I want when a user clicks edit certain page the input should contain tags related to that page.</p>
  
  <p>I mean something like this below</p>
  
  <p><a href="https://i.stack.imgur.com/CumgE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CumgE.png" alt="enter image description here"></a></p>
  
  <p>Now when a user clicks to edit a certain page the input is empty</p>
  
  <p>Here is my solution</p>
  
  <p>edit.blade (just tag input with custom js)</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;select class="js-example-basic-multiple form-control" name="tags[]" multiple="multiple"&gt;
  
          @foreach ($tags as $tag)
  
          &lt;option value="{{ $tag-&gt;id }}"&gt;{{$tag-&gt;name}}&lt;/option&gt;
  
          @endforeach
   &lt;/select&gt;
  @section('script')
  
  {!! Html::script('js/select2.js') !!}
  
  &lt;script type="text/javascript"&gt;
  
      $('.js-example-basic-multiple').select2();
      $('.js-example-basic-multiple').select2().val({!! json_encode($pages-&gt;tags()-&gt;getRelatedIds()) !!}).trigger('change');
  
  &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>Here is my page list controller (just function for editing)</p>
  
  <pre><code> public function edit($id)
      {
          $pages = PageList::find($id);
          $tags =PageListTag::all();
  
          return view('pages.edit', ['pages' =&gt; $pages, 'tags' =&gt; $tags]);
      }
  </code></pre>
  
  <p>Here in my Tag controller</p>
  
  <pre><code>class TagController extends Controller
  {
      public function index()
      {
          $tags = Tag::all();
          $pages = PageList::all();
          return view('pages.index', compact('tags', 'pages'));
      }
  
      public function store(Request $request)
      {
          $this-&gt;validate($reguest, array('name'=&gt;'required|max:255'));
          $tag = new Tag;
          $tag-&gt;name = $request-&gt;name;
          $tag-&gt;save();
          $request-&gt;session()-&gt;flash('succes', 'Tag was successful created!');
          return redirect()-&gt;route('pages.index');
      }
  }
  </code></pre>
  
  <p>Here is my page list model </p>
  
  <pre><code>class PageList extends Model
  {  
      protected $fillable = [
          'pagetitle',
          'articlelist',
          'status',
          'prebid',      
      ];
  
      public function tags(){
          return $this-&gt;belongsToMany('App\PageListTag');
      }
  }
  </code></pre>
  
  <p>Here is my PageListTag model</p>
  
  <pre><code>class PageListTag extends Model
  {
      public function pagelist()
      {
          return $this-&gt;belongsToMany('App\PageList');
      }
  }
  </code></pre>
  
  <p>Now when I run my app I have the following error</p>
  
  <pre><code>Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsToMany::getRelatedIds() (View: C:\custom-xammp\htdocs\royalad-dashboard\resources\views\pages\edit.blade.php)
  </code></pre>
  
  <p>What am I doing wrong in my codes?</p>