Подтвердить что ты не робот

Конструкция контроллера Laravel

Я начал с laravel несколько дней назад, и я столкнулся с этой проблемой:

NO никогда не возвращается!

Это Controller, есть ли у вас какие-либо идеи, почему?

  Class TestController extends BaseController {

    public function __construct()
    {
        if (!Auth::check()) return 'NO';
    }

    public function test($id)
    {   
        return $id;
    }
}
4b9b3361

Ответ 1

<?php

class BaseController extends Controller {

    public function __construct()
    {
        // Closure as callback
        $this->beforeFilter(function(){
            if(!Auth::check()) {
                return 'no';
            }
        });

        // or register filter name
        // $this->beforeFilter('auth');
        //
        // and place this to app/filters.php
        // Route::filter('auth', function()
        // {
        //  if(!Auth::check()) {
        //      return 'no';
        //  }
        // });
    }

    public function index()
    {
        return "I'm at index";
    }
}