Controller.php 1.36 KB
Newer Older
jhon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?php

namespace Acacha\AdminLTETemplateLaravel\Console\Routes;

/**
 * Class Controller.
 *
 * @package Acacha\AdminLTETemplateLaravel\Console\Routes
 */
trait Controller
{
    /**
     * Obtain controller.
     *
     * @param $controllername
     * @return string
     */
    protected function controller($controllername)
    {
        if (str_contains($controllername, '/')) {
            $controllername = str_replace('/', '\\', $controllername);
        }

        if (str_contains($controllername, '@')) {
            return ucfirst($controllername);
        }
        return ucfirst($controllername . '@index');
    }

    /**
     * Obtain controller.
     *
     * @param $controllername
     * @return string
     */
    protected function controllerWithoutMethod($controllername)
    {
        if (str_contains($controller = $controllername, '@')) {
            return ucfirst(substr($controllername, 0, strpos($controllername, '@')));
        }
        return ucfirst($controllername);
    }

    /**
     * Get method from controller name.
     *
     * @param $controllername
     * @return string
     */
    protected function controllerMethod($controllername)
    {
        if (str_contains($controller = $controllername, '@')) {
            return substr($controllername, strpos($controllername, '@')+1, strlen($controllername));
        }
        return 'index';
    }
}