I personally use the class / template approach, but you can use share method too, i register them like so:
Service Provider
use Illuminate\Contracts\View\Factory as ViewFactory;
public function boot(ViewFactory $view)
{
// All view Share - (Global)
$view->composer('*','App\Http\ViewComposer\MasterSiteComposer');
// Top NavBar
$view->composer('layouts.site.partials._navbar','App\Http\ViewComposer\NavBarComposer');
// User Cover
$view->composer('site.user.partials.profile.cover','App\Http\ViewComposer\UserCover');
// Show Cover
$view->composer('site.show.partials.profile.cover','App\Http\ViewComposer\ShowCover');
// View share
$view->share('hello','helloString');
}
In the class referenced in the composer method we are going to have a method called composer(View $view) and there you can pass variables to the view, example:
use Illuminate\View\View;
public function compose(View $view)
{
$dataToBeShared = 'Hello';
$view->with('variable', $dataToBeShared); // $variable will be the shared data in your view
}