尝试通过数据透视表i Laravel连接类别和用户

I have users and categories tables and pivot table categorie_users in database. In controller I make that every user can create your own categories and I make check if some category exist and if logged user have that category, he can't create new category with same name and that works fine. So next what I want is 'else' - if category exist and logged user don't have that category but he want to create it - in that case I want to connect that category which already exist and that user. Other words - I want to, let's say, category 'Music' to be just one category with that name for all future users. This is so complicated so any suggestions will appreciate. Thanks. This is my CategoriesController.php

   public function store(Request $request)
{
    $user = Sentinel::getUser();

    $category = Categories::where('name', $request->name)->get();

    foreach ($category as $cat){
        $user = CategorieUser::where('categorie_id',$cat->id)->where('user_id', $user->id);
    }

    if($category->count() > 0){
        if($user->count() > 0){
            return redirect()->route('categories.index');
        }
        else{

            /*THIS IS THAT 'else' FROM ABOVE QUESTION*/

        }
    }
    else{
        $categories = new Categories();
        $categories->name = $request->name;
        $categories->sections_id = $request->sections_id;
        $categories->save();
        $categories->users()->sync([$user->id]);
    }       
    session()->flash('success', "New category '{$categories->name}' has been created.");
    return redirect()->route('categories.index');
}

And this is my model Categories.php

   <?php

    namespace App\Models;

    use Illuminate\Database\Eloquent\Model;

    class Categories extends Model
    {
       protected $table = 'categories';

      public function sections()
      {
        return $this->belongsTo('App\Models\Sections');
      }

      public function users()
      {
        return $this->belongsToMany('App\Models\Users', 'categorie_user','categorie_id','user_id');
     }

   }

This is model Users.php

    <?php

    namespace App\Models;

    use Illuminate\Database\Eloquent\Model;

    class Users extends Model
    {
         protected $table = 'users';


      public function categories()
      {
        return $this->belongsToMany('App\Models\Categories', 'categorie_user','user_id','categorie_id');
      }

  }

And this is pivot model CategorieUser.php (which I must create that I can go through foreach loop)

   <?php

    namespace App\Models;

    use Illuminate\Database\Eloquent\Model;

    class CategorieUser extends Model
    {
        protected $table = 'categorie_user';


      public function categories(){
       return $this->belongsTo('App\Models\Categories', 'categorie_id');
      }

    }