Q:

How to retrieve the view name in Laravel 5?

I've tried a variety of ways, including the popular post here: Add View Name to CSS Class on Body
But it pulls up the master template, rather than the sub-template name. I use @yield and @extends and such. So at the moment this is what a part of my file system looks like in my views:
-Views
--Layouts
---=master.blade.php
--Shipments
---=index.blade.php

So my shipments.index file will @extends('layouts.master'), just so I don't have so much redundancy. However, referencing the above post, I get the following result:
<div id="page" class="layouts.master">
which is not what I'd like, I'd prefer at the very least "shipments.index", I don't mind if it's longer, I just want it identified.

A:

You can use Laravel View Composers

View composers are callbacks or class methods that are called when a
  view is rendered. If you have data that you want to be bound to a view
  each time that view is rendered, a view composer can help you organize
  that logic into a single location.

In the file app/Providers/AppServiceProvider.php, edit the public function boot() method
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot(Application $app)
{
    view()->composer('*', function($view) {
        view()->share('view_name', $view->getName());
    });
}

After this, in any blade template you will now have access to a variable
{{ $view_name }}

