Signrap上的Laravel 5.6路由404错误

时间:2018-05-26 21:37:17

标签: php laravel

似乎无法弄清楚这条路线的问题。返回404错误。我检查了路线列表表,他的路线在里面。因为我得到404我假设有一个路由错误,可能是一个错字但我没有看到任何东西。我更新了这篇文章以显示我的刀片文件...

| Domain | Method   | URI      | Name   | Action                                         | Middleware   |
+--------+----------+----------+--------+------------------------------------------------+--------------+
|        | GET|HEAD | /        |        | Closure                                        | web          |
|        | GET|HEAD | api/user |        | Closure                                        | api,auth:api |
|        | POST     | signup   | signup | App\Http\Controllers\UserController@postSignUp | web          |
+--------+----------+----------+--------+------------------------------------------------+--------------+

UserController中:     

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

class UserController extends Controller
{
    /**
     * @param Request $request
     */
    public function postSignUp(Request $request)
    {
        $email = $request['email'];
        $username = $request['username'];
        $password = bcrypt($request['password']);

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

        $user->save();
        return redirect()->back();
    }

    public function postSignIn(Request $request)
    {

    }
}

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

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

welcome.blade.php:

@extends('layouts.master')

@section('title')
    Welcome!
@endsection
@section('content')
<div class ="row">
    <div class="col-md-6">
        <h3>Sign Up</h3>
        <form action="{{route('signup')}}" method="post">
            <div class="form-group">
                <label for="email">Email:</label>
                <input class="form-control" type="text" name="email" id="email">
            </div>
            <div class="form-group">
                <label for="username">UserName:</label>
                <input class="form-control" type="text" name="username" id="username">
            </div>
            <div class="form-group">
                <label for="password">Password:</label>
                <input class="form-control" type="password" 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>

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

            <div class="form-group">
                <label for="password">Password:</label>
                <input class="form-control" type="password" name="password" id="password">
            </div>
            <button type="submit" class="btn btn-primary">Submit</button>
        </form>
    </div>


@endsection

master.blade.php:

@extends('layouts.master')

@section('title')
    Welcome!
@endsection
@section('content')
<div class ="row">
    <div class="col-md-6">
        <h3>Sign Up</h3>
        <form action="{{route('signup')}}" method="post">
            <div class="form-group">
                <label for="email">Email:</label>
                <input class="form-control" type="text" name="email" id="email">
            </div>
            <div class="form-group">
                <label for="username">UserName:</label>
                <input class="form-control" type="text" name="username" id="username">
            </div>
            <div class="form-group">
                <label for="password">Password:</label>
                <input class="form-control" type="password" 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>

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

            <div class="form-group">
                <label for="password">Password:</label>
                <input class="form-control" type="password" name="password" id="password">
            </div>
            <button type="submit" class="btn btn-primary">Submit</button>
        </form>
    </div>

@endsection

3 个答案:

答案 0 :(得分:0)

您忘记在UserController类中设置名称空间

答案 1 :(得分:0)

首先设置php artisan服务然后更改所有htdoc指令以允许所有

答案 2 :(得分:-2)

你应该运行“php artisan make:auth”