Php 用户找不到为什么?

Php 用户找不到为什么?,php,laravel,Php,Laravel,在那里,我遵循了Laravel教程来路由模型绑定。但是我偶然发现了一个错误,为什么会这样,所以我这里有代码。请在这里找到并列出一个有效的修复方法。视频可以在我的求职者,路线模型绑定第11集找到 TaskController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\User; class TaskController extends

在那里,我遵循了Laravel教程来路由模型绑定。但是我偶然发现了一个错误,为什么会这样,所以我这里有代码。请在这里找到并列出一个有效的修复方法。视频可以在我的求职者,路线模型绑定第11集找到

TaskController.php

    <?php
    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use App\User;

    class TaskController extends Controller {
        public function index(){
            return User::all();
        }
    }
    <?php
    namespace App\Models;

    use Illuminate\Contracts\Auth\MustVerifyEmail;
    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Illuminate\Notifications\Notifiable;

    class User extends Authenticatable {
        use HasFactory, Notifiable;

        /**
         * 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',
        ];

        /**
         * The attributes that should be cast to native types.
         *
         * @var array
         */
        protected $casts = [
            'email_verified_at' => 'datetime',
        ];
    }
    <?php
    use Illuminate\Support\Facades\Route;
    use App\User;
    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */

    Route::get('/', function () {
        return view('welcome');
    });

    Auth::routes();

    Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

    Route::get('/user', [App\Http\Controllers\TaskController::class, 'index']);

只需检查模型的名称空间


替换使用App\User使用App\Models\User

在Laravel-8中,
User.php
文件从
app
文件夹移动到
app/Models
,因此当您想要像这样调用用户模型时,请使用app\Models\User不像这样
使用App\User

您的用户模型在Models文件夹内或?namespace App\Models外;因此,在控制器中使用App\Models\User之类的错误消息是什么?您希望访问哪个URI?请发布一个,以便我们可以帮助您。