raunak-gupta
10/11/2016 - 8:06 AM

Laravel Helper function to get current controller name. This code can be written in app/Helpers/Helpers.php.

Laravel Helper function to get current controller name. This code can be written in app/Helpers/Helpers.php.

<?php

if (!function_exists('getControllerName')) {
    function getControllerName($string) {
        $pices = explode('\\', $string);
        $pices1 = explode('@', end($pices));
        $controller_name = current($pices1);
        return ucfirst(str_replace('Controller', '', $controller_name));
    }
}