2
votes

I am new to Laravel. I am learning how to create user registration page. Everything works fine but I am stuck in a simple problem.

ErrorException in UrlGenerator.php line 304: Route [signup] not defined. (View: C:\Program Files (x86)\Ampps\www\social\resources\views\welcome.blade.php)

But I defined signup route. Here is my routes.php file

Route::get('/', function () {
  return view('welcome');
})->name('home');
Route::post('/signup', [
    'uses' => 'UserController@postSignUp',
    'as' => 'signup'
]);

And this is my UserController.php

class UserController extends Controller
{
    public function postSignUp(Request $request)
    {
        $email = $request['email'];
        $first_name = $request['frist_name'];
        $password = bcrypt($request['password']);


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

        $user->save();

        return redirect()->back();

Blade file is welcome.blade.php

 <form action="{{ route('signup') }}" method="post">
         <div class="form-group">
           <label for="email"> Your E-mail </label>
           <input class ="form-control" type="text" id="email" name="email" >
         </div>

I would be much obliged if anyone could help me. Thanks

Oh, Sorry. I forget to mention that I am using Laravel version: 5.4.11

5
Try running composer install and php artisan route:clear. - Stuart Wagner
Route::post('/signup', ['as' => 'signup','uses'=>'UserController@postSignUp']); and the form action is <form action="{{ url('/register') }}" method="post"> use this it will work... - Soniya Basireddy
Thank you @StuartWagner I did all but it does not work :( - Maruf Alom
Try php artisan route:list and make sure your 'signup' route shows up. - Stuart Wagner
@Sona Yes, It shows the welcome page but when I am submitting data through form it says NotFoundHttpException in RouteCollection.php line 161 - Maruf Alom

5 Answers

3
votes

You can change {{route('/signup')}} to {{URL('/signup')}}

<form action="{{ URL('signup') }}" method="post">
    <div class="form-group">
    <label for="email"> Your E-mail </label>
   <input class ="form-control" type="text" id="email" name="email" >
  </div>
1
votes

laravel provide inbuilt auth functionality, you type following command in your terminal after select project:

php artisan make:auth

and you can use login,register and changes password functionality.

reference:

https://laravel.com/docs/5.4/authentication

i hope its help you

1
votes

Just for the completeness, as @StuartWagner replied since of Laravel 5.4 all routes are inside the /routes folder and not any more inside the HTTP folder.

The web routes are inside the /routes/web.php file.

This was often requested since otherwise, you would need to browse three levels deep to get the routes.

Now much better, they are in the /routes folder.

0
votes

Try

<form action="/signup" method="POST">
         <div class="form-group">
           <label for="email"> Your E-mail </label>
           <input class ="form-control" type="text" id="email" name="email" >
         </div>
0
votes

I know it's a bit old but want to contribute :)

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

add a name for route

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

When you are using the route inside your blade template then you have to give the name to your route to identify

<form action="{{ route('signup') }}" method="post">
         <div class="form-group">
           <label for="email"> Your E-mail </label>
           <input class ="form-control" type="text" id="email" name="email" >
         </div>