-1
在laravel我讓TrainingRequest文件驗證和我做出如下創建文件驗證: -命名空間聲明語句必須在腳本中使用</p> <pre><code>php artisan make:request TrainingRequest FatalErrorException in TrainingRequest.php line 3: Namespace declaration statement has to be the very first statement in the script </code></pre> <p>的第一個語句Laravel-5
<?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');
}
什麼是請求文件的編碼?它是UTF-8嗎? – Burak
它是一個php文件。如何知道文件的編碼類型? Burak先生 –
看到這個:http://programmers.stackexchange.com/questions/187169/how-to-detect-the-encoding-of-a-file – Burak