表单请求不适用于Controller文件夹

时间:2015-08-21 05:37:56

标签: laravel-5

我的控制器文件夹结构是:
controller folder structure

我使用以下路由代码来访问这些控制器。

这里我已经在Controller文件夹中分配了子文件夹,并根据需要在文件和路由上更新了命名空间,这非常有效,但是当我使用请求文件验证表单时。它给出了错误:

Argument 1 passed to App\Http\Controllers\site\usersController::store()
must be an instance of Illuminate\Http\Request, string given

但是当我将所有控制器文件移动到Controller文件夹并且不使用子文件夹时,表单请求验证工作。我的usersController和UserRegReq请求文件是:

usersController.php

<?php

namespace App\Http\Controllers\zcms;

use Illuminate\Http\Request;
use App\Services\FieldService;
use App\Services\UserService;
use App\Http\Requests;
use App\Http\Requests\UserRegReq;
use App\Http\Controllers\Controller;

class usersController extends Controller {

    public function __construct(FieldService $field, UserService $user)
    {

        $this->field = $field;
        $this->user = $user;
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function throwLogin()
    {

        return view('zcms.pages.login');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        $field = $this->field->fieldList();

        return view('zcms.users.addnew', compact('field'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  Request $request
     * @return Response
     */
    public function store(UserRegReq $request)
    {
        return "hello";
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  Request $request
     * @param  int $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }
}

UserRegReq.php

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserRegReq 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 [
            'field_id' => 'required',
            'name'     => 'required',
            'username' => 'required',
            'password' => 'required'
        ];
    }


    // public function messages(){
    //     return [
    //         'field_id.required'=>'The related Field of your Job is required',
    //     ];
    // }
}

除了更新路由和控制器文件中的命名空间以使一切正常工作外,我该怎么办?

0 个答案:

没有答案