Created
November 28, 2017 03:16
-
-
Save phegman/58d674cec6368aa3ff6ad692000ba1d5 to your computer and use it in GitHub Desktop.
Laravel - body class based on view name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="{{ app()->getLocale() }}"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<!-- CSRF Token --> | |
<meta name="csrf-token" content="{{ csrf_token() }}"> | |
<title>{{ config('app.name', 'Laravel') }}</title> | |
<!-- Styles --> | |
<link href="{{ asset('css/app.css') }}" rel="stylesheet"> | |
@routes | |
</head> | |
<body class="{{ $viewName }}"> | |
<div id="app"> | |
@yield('content') | |
</div> | |
<!-- Scripts --> | |
<script src="{{ asset('js/app.js') }}"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Support\Facades\View; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
View::composer('*', function ($view) { | |
View::share('viewName', str_replace('.', '-', $view->name())); | |
}); | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment