Undefined variable $categories

I have a problem with my code, I’m very new to this, so I’m having trouble finding the problem.

I want my categories to be displayed, so I can select one and assign it to the keyword, the site tells me that my categories are not defined


public function store(Request $request)
{

    $motsCles = Mot_Cles::all();
    $categories = Categories::all(); 

    
    $request->validate([
        'mot' => 'required|string|max:255',
    ]);


    
    $motCle = Mot_cles::create([
        'mot' => $request->input('mot'),
    ]);

    $category = Categories::find($request->category);
    $motCle->categories()->attach($category);



    return view('Mots_Cles', compact('categories'));
    return view('Mots_Cles', compact('motsCles'));


    event(new Registered($motCle));
    return redirect(RouteServiceProvider::HOME);
}

I tried to define the categories but everything seems to be fine, I wonder if it has something to do with the routes