title: Call to undefined function App\Http\Controllers\categories() in Laravel
body: <p>Please I need help, I am working on a project in Laravel, I encounter a problem when T tried to use a pivot table in manay-to-many </p>
  
  <p>In my <code>category model</code> <code>Category.php</code>, I have the function below</p>
  
  <pre><code>public function users()
  {
      return $this-&gt;belongsToMany(user::class);
  }
  </code></pre>
  
  <p>In my <code>user model</code> <code>User.php</code>, I have the function below</p>
  
  <pre><code>public function authors()
  {
      return $this-&gt;belongsToMany(author::class);
  }
  </code></pre>
  
  <p>In <code>web.php</code>, I have this</p>
  
  <pre><code>Route::post('/onboarding', 'OnboardsController@categoryUser');
  </code></pre>
  
  <p>In my <code>onboarding view</code>, I have a form:</p>
  
  <pre><code>   &lt;form action="{{ url('/onboarding') }}" method="POST"&gt;
      @csrf
        @foreach($categories as $category)
          &lt;div class="radio-item"&gt;
          &lt;input class="form control" name="category_id" type="checkbox" id="category_id" required&gt;
            &lt;label for="name"&gt;{{ $category -&gt; title }}&lt;/label&gt;
          &lt;/div&gt;
          @endforeach
  
          &lt;div class="form-row"&gt;
            &lt;div class="form-group col-md-12 text-center"&gt;
              &lt;button type="submit"&gt;Proceed to Authors&lt;/button&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p>In my <code>OnboardsController</code></p>
  
  <p>I have this</p>
  
  <pre><code>public function categoryUser (Request $request)
  {
    $user = User::findOrFail(Auth::user()-&gt;id);
    $user = categories()-&gt;attach($request-&gt;input('category_id'));
  
    return redirect ( route ('onboarding_author')); 
  }
  </code></pre>
  
  <p>This is the returned error:</p>
  
  <blockquote>
    <p>Call to undefined function App\Http\Controllers\categories()</p>
  </blockquote>
  
  <p>When I change the code in my controller to </p>
  
  <pre><code>$category = Category::find($request-&gt;input('category_id'));
  $user = User::where('user_id', Auth::id());
  $category-&gt;users()-&gt;attach($user-&gt;id);
  </code></pre>
  
  <p>This is the returned error:</p>
  
  <blockquote>
    <p>Call to undefined function App\Http\Controllers\users()</p>
  </blockquote>
  
  <p>Here is my full <code>OnboardsController.php</code> code </p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  use Illuminate\Support\Facades\Auth;
  use Illuminate\Http\Request;
  use App\Author;
  use App\User;
  use App\Category;
  
  
  class OnboardsController extends Controller
  {
  public function index()
          {
      //
      return view('onboarding')
      -&gt;with('categories', Category::all());
  
  }
  
  public function author()
  {
  //
  return view('onboarding_author')
  -&gt;with('authors', Author::all());
  
  }
  
  public function categoryUser (Request $request)
  {
  
      dd(request('category_id'));
      Category::findOrFail(request('category_id'))
      -&gt;users()
      -&gt;attach(auth()-&gt;user()-&gt;id);
  
      return redirect ( route ('onboarding_author')); 
  }
  </code></pre>
  
  <p>Please I am new to Laravel and I have been on this for 3 days, I don't know how to solve this. I need help.</p>