RouteCollection.php第161行中的Laravel NotFoundHttpException:

I'm having a hard time on this error when I encounter this error, My solution is to create new project. I know this question is alway ask here. I followed all tutorial line by line and is always error.

Sign Up:

 @extends('layouts.master')
 @section('content')
  <div class="col-md-6">
    <form method="POST" action="{{ route('signup') }}">
        <div class="form-group">
            <input type="text" name="username" placeholder="Username" class="form-control"></input>
        </div>
        <div class="form-group">
            <input type="password" name="password" placeholder="Password" class="form-control"></input>
        </div>
        <div class="form-group">
            <input type="submit" value="Submit" class="btn btn-primary pull-right"></input>
            <input type="hidden" name="_token" value="{{ Session::token() }}"></input>
        </div>
    </form>
</div>
@endsection

routes.php

 <?php

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

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

UserController

 <?php

 namespace App\Http\Controllers;
 use Illuminate\Http\Request;
 use App\Http\Requests;
 use App\User;

 class UserController extends Controller
 {
 public function postSignUp(Request $request){

    $username = $request['username'];
    $password = bcrypt($request['password']);

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

    return redirect()->back();
  }
}

I don't see a get route for your form. Your post route will work only if you submit the form.

So, in your routes.php, there should something like

   <?php

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

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

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

And, in UserController@getSignUp you just load the view of the form.

//your blade file is OK ,you can use same

//you route

Route::get('/signup', function () {     //route1 to view form
    return view('signUp');
});

Route::post('/signup', [               // route2 to handle form request
    'uses' => 'UserController@postSignUp',
    'as' => 'signup'
]);

to view your form you have to use get method which is route1 ,after submitting the form your postSignUp method will redirect to get route which is route1.

//your controller

public function postSignUp(Request $request){
$username = $request->username;      //to access username 
$password = bcrypt($request->password); //to access password



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

return redirect()->back();
}

in your blade file you use name filed as username and password for user's username and password respectively.so In user Usercontroller you can directly access them as $request->username and $request->password for User's username and password respectively.