It's just same name for method, behind the scene they use different classes.
When you redirect() so with() is for flash data.
Flash data: https://laravel.com/docs/7.x/responses#redirecting-with-flashed-session-data
When you return view() then with() is used for pass data to the view.
Views: https://laravel.com/docs/7.x/views#passing-data-to-views