Php 名称空间声明语句必须是Laravel-5脚本中的第一条语句
在laravel中,我使用Php 名称空间声明语句必须是Laravel-5脚本中的第一条语句,php,laravel,Php,Laravel,在laravel中,我使用 php artisan make:request TrainingRequest FatalErrorException in TrainingRequest.php line 3: Namespace declaration statement has to be the very first statement in the script 我在创建的文件中进行验证,如下所示:- <?php namespace App\Http\Reques
php artisan make:request TrainingRequest
FatalErrorException in TrainingRequest.php line 3:
Namespace declaration statement has to be the very first statement in the script
我在创建的文件中进行验证,如下所示:-
<?php
namespace App\Http\Requests; <!--This is line number 3 -->
use App\Http\Requests\Request;
class TrainingRequest extends Request
{
/**
* 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 [
'topic' => 'required|min:3',
'sub_topic' => 'required',
'category' => 'required',
];
}
}
<?php
namespace App\Http\Controllers;
use App\Training;
use App\User;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\TrainingRequest;
use Request;
class TrainingController extends Controller
{
public function store(TrainingRequest $request)
{
//store Training
//$training=Request::all();
Training::create($request->all());
return redirect('training');
}
在起始php标记之前有一个空格
解决方案只需清除空格请求文件的编码是什么?它是UTF-8吗?它是一个php文件。如何知道文件的编码类型?Burak sirsee:是的,这是UTF-8编码,你肯定缺少空格或一些字符,你发布的代码看起来很有希望,我看不出有任何问题。