我创建users.blade.php时在Laravel中找不到类“ App \ users”

时间:2019-01-23 10:29:46

标签: php laravel

我遇到以下错误:

  

usercontroller.php第21行中的FatalErrorException:未找到类“ APP \ User”

usercontroller.php:

<?php

namespace App\Http\Controllers;
use APP\User;
use Illuminate\Http\Request;
use App\Http\Requests;


class usercontroller extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $user = User::all();
        return view('admin/users', compct('user'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

User.php(位于App / User.php中):

<?php

namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

我创建了 users.blade.php 以便在管理面板中列出该用户,但最后我单击了一个用户,然后他们在屏幕上出现错误,请说我该怎么做

3 个答案:

答案 0 :(得分:2)

错字

use APP\User;更改为use App\User;

这是区分大小写的,因此它们不是一回事。

答案 1 :(得分:1)

请在UserController中将用户类与此命名空间 App / User NOT APP / user

答案 2 :(得分:1)

use APP\User;更改为use App\User;

也将计算更改为 compact

public function index()
{
    $user = User::all();
    return view('admin/users', compact('user'));
}