<?php

use Illuminate\Support\Facades\Route;

Route::get('login', 'Auth\LoginController@showLoginForm')->name('teacher.login');
Route::post('login','Auth\LoginController@login');
Route::get('logout', 'Auth\LoginController@logout');


Route::group(['middleware' => ['auth.teacher']], function() {

    $uri =  request()->path();
    $uri = str_replace('teacher/' ,'', $uri);
    $uri = str_replace('teacher' ,'', $uri);
    if ($uri == '') {
        Route::any('/', ['as' => 'admin',
            'uses' => 'Base\IndexController@index']);
    } else {
        $aUri = $baseUri = explode('/', $uri);
        if (count($aUri) > 1) {
            unset($aUri[count($aUri) - 1]);
            $file = app_path() . '/Http/Controllers/Teacher/' . implode("/", $aUri) . "Controller.php";
            if (file_exists($file)) {
                $controller = implode("\\", $aUri) . "Controller";
                $action = $controller . "@" . $baseUri[count($aUri)];
                Route::any($uri, ['as' => 'teacher',
                    'uses' => $action]);
            }
        }

    }

});