Route.php第280行中的ReflectionException:方法App \ Http \ Controllers \ UserController :: Signup()不存在

时间:2018-05-26 07:30:16

标签: laravel controller routes

我是laravel的新程序员。我目前正在使用laravel 5.2。当我试图将数据输入到我创建为welcome.blade.php的表单时,我遇到了这个错误。我检查了路线,似乎很好。我不知道我可能做错了什么。这是问题显示 Route.php第280行中的ReflectionException: 方法App \ Http \ Controllers \ UserController :: Signup()不存在

UserController中

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{

    public function postSignUp(Request $request)
    {
        $email = $request['email'];
        $first_name = $request['first_name'];
        $password = bcrypt($request['password']);

        $user = new User();
        $user->email = $email;
        $user->first_name = $first_name;
        $user->password = $password;

        $user->save();

        return redirect()->back();
    }

    public function postSignIn(Request $request)
    {

    }
}

路线

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::group(['middleware' => ['web']], function () {
    Route::get('/', function () {
        return view('welcome');
    });

    Route::post('/signup', [
        'uses' => 'UserController@Signup',
        'as'   => 'signup',
    ]);
});

welcome.blade.php

@extends('layouts.master')
@section('title')
    Welcome!
@endsection
@section('content')
    <div class="row">
        <div class="col-md-6">
            <h2>Sign Up</h2>
            <form action="{{route('signup')}}" method="post">
                <div class="form-group">
                    <label for="email">Your Email</label>
                    <input class="form-control" type="text" name="email" id="email">
                </div>

                <div class="form-group">
                    <label for="first_name">Your First Name</label>
                    <input class="form-control" type="text" name="first_name" id="first_name">
                </div>

                <div class="form-group">
                    <label for="password">Your Password</label>
                    <input class="form-control" type="text" name="password" id="password">
                </div>

                <button type="submit" class="btn btn-primary">Submit</button>
                <input type="hidden" name="_token" value="{{Session::token()}}">
            </form>
        </div>

        <div class="col-md-6">
            <h2>Sign In</h2>
            <form action="#" method="post">
                <div class="form-group">
                    <label for="email">Your Email</label>
                    <input class="form-control" type="text" name="email" id="email"></div>

                <div class="form-group">
                    <label for="password">Your Password</label>
                    <input class="form-control" type="text" name="password" id="password"></div>

                <button type="submit" class="btn btn-primary">Submit</button>
            </form>
        </div>
    </div>
@endsection

2 个答案:

答案 0 :(得分:0)

你根据路线使用不同的功能名称,两者都是一样的。 用以下内容替换您的函数名称: -

postSignUp to SignUp

答案 1 :(得分:0)

感谢您的建议,我将postSignUp更改为userController中的SignUp

public function postSignUp(Request $request)
change to
 public function SignUp(Request $request)
also in the route I change the
 'uses' => 'UserController@Signup',
change to
 'uses' => 'UserController@SignUp',