Class' App \ users'在Laravel 5中找不到

时间:2016-05-04 14:54:37

标签: php laravel

我收到以下错误:

  

UserController.php第23行中的FatalErrorException:

     

Class' App \ Users'找不到

Usercontroller.php:

<?php

namespace App\Http\Controllers;

use Request;

use App\Users;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Validator;
use Redirect;
use Session;


class UserController extends Controller
{

   public function index()
   {
      $user=Users::all();
      return view('users.index',compact('user'));
   }


   public function edit($id)
   {
      $user=Users::find($id);
      return view('users.edit',compact('user'));
   }

   public function update($id)
   {
     $userUpdate=Request::all();
     $user=Users::find($id);
     $user->update($userUpdate);
     return redirect('users');
   }

   public function destroy($id)
   {
      Users::find($id)->Delete();
      return redirect('users');

      //Schema::table('books', function ($table) {
      //$table->softDeletes();
//});
   }

}

Users.php(在App / Users.php中):

    namespace App;

    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Database\Eloquent\SoftDeletes;


    class User extends Model
    {
        protected $fillable=[
            'name',
            'email',
            'password',
            'remember_token',
            'created_at',
            'updated_at',
            'active',
            'role'
        ];

    }

我也尝试了composer dumpautoloadphp artisan config:clear,但它似乎无法发挥作用。

2 个答案:

答案 0 :(得分:5)

\App\User,而不是\App\Users。就是这样。

您的班级名称和文件名不匹配。将课程更改为Users或将文件更改为User

答案 1 :(得分:0)

你忘了use Model。在use App\User;子句之后添加namespace

另外,将Users.php重命名为User.php

或者你可以像这样使用这个模型:

App\User::find(1);