CommanderTrait.php 第 59 行中的 ReflectionException:Class App\FollowUserCommand 不存在

ReflectionException in CommanderTrait.php line 59: Class App\FollowUserCommand does not exist

我正在关注 Laracasts 视频以创建关注选项,但是当我点击会员页面上的关注按钮时,它显示了上述错误。这是我的 followcontroller

<?php

namespace App\Http\Controllers;

use App\User;
use Laracasts\Commander\CommanderTrait;
use App\FollowUserCommand; 
use Sentinel;
use Illuminate\Support\Facades\Input;
use App\Http\Requests;
use App\Http\Controllers\Controller;


class FollowsController extends Controller
{
use CommanderTrait;
/**
 * Follow a User
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store()
{
    $input = array_add(Input::all(), 'user_id', Sentinel::getuser()->id);
    $this->execute(FollowUserCommand::class, $input);
    return Redirect::back();
}


/**
 * Unfollow a User
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    //
}
}

这是我的FollowUserCommand

<?php namespace App\User;

class FollowUserCommand {

public $user_id;
public $userIdToFollow;

function __construct($user_id, $userIdToFollow)
{
    $this->user_id = $user_id;
    $this->userIdToFollow = $userIdToFollow;
}
}

FollowUserCommandHandler

<?php namespace App;

use Laracasts\Commander\CommandHandler;

class FollowUserCommandHandler implements CommandHandler {

protected $userRepo;

function __construct(UserRepository $userRepo)
{
    $this->userRepo = $userRepo;
}




public function handle($command)
{
    $user = $this->userRepo->findById($command->user_id);

    $this->userRepo->follow($command->userIdToFollow, $user);

    return $user;
}

}

用户资料库

class UserRepository {

public function save(User $user) 
{
    return $user->save();
}

public function getPaginated($howMany = 4)
{
    return User::orderBy('first_name', 'asc')->paginate($howMany);
}

public function findByUsername($username)
{
    return User::with(['feeds' => function($query)
    {
        $query->latest();
    }

    ])->whereUsername($username)->first();
}

public function findById($id) 
{
    return User::findOrFail($id);
}

public function follow($userIdToFollow, User $user)
{
    return $user->follows()->attach($userIdToFollow);
}
}

User.php

<?php namespace App;
use Cartalyst\Sentinel\Users\EloquentUser;
use Illuminate\Database\Eloquent\SoftDeletes;


class User extends EloquentUser {


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

/**
 * The attributes to be fillable from the model.
 *
 * A dirty hack to allow fields to be fillable by calling empty fillable array
 *
 * @var array
 */
protected $fillable = [];
protected $guarded = ['id'];

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

/**
* To allow soft deletes
*/
use SoftDeletes;

protected $dates = ['deleted_at'];   

    // This function allows us to get a list of users following us
public function follows()
{
    return $this->belongsToMany(self::class, 'follows', 'follower_id', 'followed_id')->withTimestamps();
}

// Get all users we are following
public function following()
{
    return $this->belongsToMany('User', 'followers', 'user_id', 'follow_id')->withTimestamps();
}
}

谁能告诉我为什么即使在 "use App\FollowUserCommand;" 已在命名空间中声明后它仍显示错误。

你声明FollowUserCommand时的命名空间class是错误的,应该是:

<?php namespace App;

class FollowUserCommand {...

现在你有 <?php namespace App\User;.