簡體   English   中英

Route.php行339中的ReflectionException:Laravel 5.3中不存在類App \\ Http \\ Requests \\ CreateTenantRequest

[英]ReflectionException in Route.php line 339: Class App\Http\Requests\CreateTenantRequest does not exist in Laravel 5.3

我正在使用Laravel 5.3。 嘗試提交表單時出現此錯誤。 我使用了laravelcollective / html。 這是我的代碼:

路線/web.php

Route::resource('add-new-tenant', 'SuperAdmin\TenantController');

Route::resource('new-tenant', 'SuperAdmin\TenantController@store');

控制器:

 <?php

 namespace App\Http\Controllers\SuperAdmin;

 use App\Tenant;

 use App\Http\Requests;
 use App\Http\Requests\CreateTenantRequest;
 use App\Http\Controllers\Controller;

class TenantController extends Controller
{
/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return view('pages.superadmin.add-new-tenant');
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \App\Http\Requests\CreateTenantRequest  $request
 * @return \Illuminate\Http\Response
 */
  public function store(CreateTenantRequest $request)
  {
    Tenant::create($request->all());

    return redirect('add-new-tenant');
  }

}

我已經創建了一個驗證表單的請求。 代碼如下:

app / Http / Requests / CreateTenantRequest.php

 <?php

 namespace App\Http\Requests;

 use Illuminate\Foundation\Http\FormRequest;

class CreateTenantRequest extends FormRequest
{
/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return true;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'tenant_company_name' => 'required',
        'tenant_name' => 'required',
        'tenant_email' => 'required|email'
        'tenant_domain' => 'required',
        'tenant_database' => 'required'
    ];
  }
}

提交表單時出現此錯誤。

 ReflectionException in Route.php line 339:
 Class App\Http\Requests\CreateTenantRequest does not exist

我知道在聲明CreateTenantRequest時存在一些問題,但請幫助我所缺少的內容。

謝謝。

只是我的錯,當我看到這個問題時,我把頭撞在牆上,我為此浪費了四個小時,卻沒有注意到。 唯一的錯誤是在之后缺少逗號(,)

 'tenant_email' => 'required|email',

在CreateTenantRequest.php中。 這里是:

public function rules()
{
  return [
    'tenant_company_name' => 'required',
    'tenant_name' => 'required',
    'tenant_email' => 'required|email',
    'tenant_domain' => 'required',
    'tenant_database' => 'required'
   ];
 }

感謝您的幫助,對不起,這是我的錯。

在我看來一切正常。 我的猜測是Requests尚未添加到您的自動加載器中。 每當收到消息說laravel無法找到您知道的東西並且可以看到您已正確包含在類中時,要做的第一件事就是轉儲自動加載器:

composer dump-autoload

我同意@Aisha Kamran的回答。 當您的自定義表單請求中存在語法錯誤時,會發生此錯誤消息。 並不是真正有用的錯誤消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM