班级'用户'找不到Laravel 4.2 Users :: all();

时间:2016-04-28 19:58:25

标签: php sqlite laravel laravel-4 laravel-5

我只是想将我的用户表打印到页面上。我得到了一个类Users在Laravel 4.2中找不到 - 我有转储自动加载和清除编译。

我的users.php是:

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

use UserTrait, RemindableTrait;

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'users';

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = array('password', 'remember_token');
}

我的控制器文件读取(我已经编辑了代码 - 问题是这部分代码的100%,因为如果我只是将消息传递给视图就可以了:

<?php

class SearchController extends BaseController {

public function search()
{
    $search = Input::get("Search_Input");
    $search_terms = explode(",", $search);
    $search_query_type = Input::get("search_type");
    $search_type = 'null';

    if ($search_type === "Rep_Name") {
       $users = Users::all();
       return Redirect::to('/search')->with('users', $users);
     }
}

我的搜索视图包含以下代码:

    @foreach($users as $name)
        {{ $name->Name }}
    @endforeach

我的数据库有一个用户表和一个名称行。

我得到的laravel.log错误是:

  

[2016-04-28 19:32:30] production.ERROR:exception&#39; Symfony \ Component \ Debug \ Exception \ FatalErrorException&#39;通过消息&#39; Class&#39;用户&#39;找不到&#39;在/home3/circates/public_html/jon/repform/app/controllers/SearchController.php:50       堆栈跟踪:       #0 [内部函数]:Illuminate \ Exception \ Handler-&gt; handleShutdown()       #1 {main} [] []

2 个答案:

答案 0 :(得分:1)

SearchController.php 文件中,您需要将Users:all()更改为User::all(),因为您的类定义为User,如评论中所述作者:Fabio Thomaz。

class SearchController extends BaseController {

public function search()
{
    $search = Input::get("Search_Input");
    $search_terms = explode(",", $search);
    $search_query_type = Input::get("search_type");
    $search_type = 'null';

    if ($search_type === "Rep_Name") {
       $users = User::all();
       return Redirect::to('/search')->with('users', $users);
     }
}

答案 1 :(得分:1)

您的班级名称是&#34;用户&#34;文件名是&#34; users.php&#34;

将文件名更改为&#34; User.php&#34;

你可以从SearchController中调用它:

import pandas as pd
# the frames are named the same way, and rows are in the same order
# assuming item-ids are unique I've created list of indices
# which corresponds to the index of the elements from df1 in df2
df2_index = [df2['item-id'].tolist().index(df1['item-id'][x]) for x in range(len(df1))]
# now reindex df1 according to the list and reset index!
df1 = df1.reindex(df2_index).reset_index(drop=True)
# now you can simply add the missing column
df2['item-rating'] = df1['item-rating']