主控制器中的Laravel错误:显示所有功能的未定义函数


Laravel Error In HomeController: Undefined Function showing for all functions

好的,所以我是Laravel的新手,我正在做一个新的测试项目。 我正在HomeController中编写表单处理函数,几乎我调用的每个内置函数都收到未定义错误。 我在 PHPStorm 8 中工作,我什至安装了一个新的 Laravel 项目并将我的视图复制回新项目中,没有更改任何其他 Laravel配置文件。

例如:

public function addUser()
{
    $input = Input::all();
    $rules = array('first_name' => 'required',
        'last_name' => 'required',
        'home_location' => 'required',
        'username' => 'unique:username|required',
        'password' => 'required');
    $valid = Validator($input, $rules);
    if ($valid -> passes())
    {
        $user = New User();
        $user->first_name = $input['first_name'];
        $user->last_name = $input['last_name'];
        $user->home_location = $input['home_location'];
        $user->username = $input['username'];
        $password = $input['password'];
        $password = Hash::make($password);
        $user->password = $password;
        $user->save();
        return Redirect::to('admin/');
    } else {
        return Redirect::to('admin/users/')->withInput()->withErrors($valid);
    }
}

在此块中,输入、验证器、传递、保存和重定向所有报告都作为错误。

有人知道到底出了什么问题吗?

听起来您的控制器位于命名空间中。如果这是一个Laravel 5项目,则默认HomeController的命名空间为App'Http'Controllers。要访问命名空间之外的类,您需要完全限定它们(例如 'Input::all() ),或者您需要在use语句中指定类:

<?php namespace App'Http'Controllers;
use Input;
// etc.
class HomeController extends Controller {

我看到的其他可能导致错误的事情:

// missing "new" keyword:
// $valid = Validator($input, $rules);
$valid = new Validator($input, $rules);

如果这是 Laravel 5,您的用户模型可能是命名空间的,因此您也需要它。

$user = new 'App'User();