I started with laravel few days ago and I'm facing this issue:

NO美元永远不会退还!

这是Controller,你知道为什么吗?

  Class TestController extends BaseController {

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

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

推荐答案

<?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";
    }
}

Laravel相关问答推荐

Inertia React中的错误文件上传更新

Laravel将变量从模板到已发布的供应商模板

Laravel 通过 API 嵌套 url 发布

分页计数(*)查询问题

assertSee 由于 html 代码中的空格而失败

如何在 Laravel Eloquent Collection 数组之前添加一个键值对?

在 laravel 中动态更改时区

我的composer 不会完全用 Laravel 4 更新它会被artisan卡住

Laravel 5.3 创建模型返回字段没有默认值

Laravel 5在blade中 echo 包含html的会话变量

带有 Laravel Passport 的 SSO

PHP 中的 Http 响应代码枚举

Cookie::forget 不工作 laravel 5.1

Eloquent ORM,deleted_at 使用软删除时没有索引

Laravel 检测手机/平板电脑并加载正确的视图

Laravel 5 事件处理程序未触发

如何在 Laravel 中 Refresh刷新用户对象?

向 Laravel 重定向添加一个锚点

Laravel - 使用 Eloquent 查询构建器在 Select 中添加自定义列

如何在没有日志(log)、没有信息的情况下调试 Laravel 错误 500