0

First And For most, I wouldn't ask here if I didn't do some research myself yet, I saw many similar titled Questions, but they seem to not be the same problem that I have.

=Actual Start=

So I am following this Web Tutorial Series called Laravel 5.2 PHP Build a social network and I am stuck at the end of the third episode. My problem is that when I try to click the Sign Up Button, I get this Error:

1/1
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 755
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54

I tried Fixing the web.php , welcome.blade.php, UserController.php

Can anyone help me understand what is wrong?

web.php

<?php

/*
|--------------------------------------------------------------------------
| 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'
]);

UserController.php

<?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){
        $email = $request['email'];
        $password = $request['password'];
    }
}

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">Your Email</label>
                    <input type="form-control" type="text" name="email" id="email">
                </div>
                <div class="form-group">
                    <label for="first_name">Your First Name</label>
                    <input type="form-control" type="text" name="first_name" id="first_name">
                </div>
                <div class="form-group">
                    <label for="password">Your Password</label>
                    <input type="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 class="col-md-6">
            <h3>Sign In</h3>
            <form action="#" method="post">
                <div class="form-group">
                    <label for="email">Your Email</label>
                    <input type="form-control" type="text" name="email" id="email">
                </div>
                <div class="form-group">
                    <label for="password">Your Password</label>
                    <input type="form-control" type="password" name="password" id="password">
                </div>
                <button type="submit" class="btn btn-primary"> Submit</button>
            </form>
        </div>
    </div>
@endsection

Go this when I ran: php artisan route:list

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

EDIT 11/21/2016 07:00 PM: It should be worth noting that while I am using Laravel 5.3, I'm not sure what the Presenter was using, but he was using a projec that has routes.php, i just tried to work around by using the web.php since it seems to be the closest thing to what i need to follow along the tutorial. I also have the link as http://localhost/hiro/public/

Akira Hora
  • 458
  • 1
  • 6
  • 18
  • Can you run `php artisan route:list` please – James Nov 21 '16 at 10:19
  • This could be what you wanted: | POST | signup | signup | App\Http\Controllers\UserController@postSignUp | web – Akira Hora Nov 21 '16 at 10:26
  • that error because you are accessing that route in GET method but in your code in route you only allowed method POST `Route::post('/signup',` to allowed other method in that url `Route::match('GET', 'POST', 'PUT', etc...)` – Beginner Nov 21 '16 at 10:31
  • @NewbeeDev I don't think so. That would lead to MethodNotAllowedHttpException and not to NotFoundHttpException. – sleepless Nov 21 '16 at 10:38
  • @NewbeeDev I'm sorry, where in my code did you see GET? I plan on only using POST methods in regards to this. aside from the return view('welcome') – Akira Hora Nov 21 '16 at 10:40
  • I'm sorry, in my asnwer a made an error, it should be POST, not GET. I corrected it. – GiuServ Nov 21 '16 at 10:51
  • @sleepless right! True `return back()` instead! With `->withInput(); ` if you want also the parameter in the form, but you shouldn't need them – GiuServ Nov 21 '16 at 11:02
  • maybe the problem is your form action. isn't that should `http://localhost/hiro/signup` ? also I think you need a change in ht.access to set your public as your index folder – Beginner Nov 21 '16 at 11:02
  • @NewbeeDev Sorry, changed it to the base folder – Akira Hora Nov 21 '16 at 11:10

2 Answers2

0

It seems that there's nothing wrong with the route itself.

This is really just a guess for me but worth giving a shot:

web.php

<?php 

// Removed a forward slash from the route
Route::post('signup', [
    'uses' => 'UserController@postSignUp',
    'as' => 'signup'
]);

welcome.blade.php

        <div class="col-md-6">
            <h3>Sign Up</h3>
            <!-- Use a regular HTML route instead of Laravel's own -->
            <form action="/signup" method="POST">
                <div class="form-group">
                    <label for="email">Your Email</label>
                    <input type="form-control" type="text" name="email" id="email">
                </div>
                <div class="form-group">
                    <label for="first_name">Your First Name</label>
                    <input type="form-control" type="text" name="first_name" id="first_name">
                </div>
                <div class="form-group">
                    <label for="password">Your Password</label>
                    <input type="form-control" type="password" name="password" id="password">
                </div>
                <!-- Changed the submit button to input element instead of button -->
                <input type="submit" class="btn btn-primary" value="Submit">
                <input type="hidden" name="_token" value="{{Session::token()}}">
            </form>
        </div>
B_CooperA
  • 659
  • 1
  • 9
  • 28
  • Different error. Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. – Akira Hora Nov 21 '16 at 10:54
  • What happens if you try to change the route to `GET` for testing purposes and try returning something? F.e: `Route::get('/signup', function () { return "Hello World!"; });`. Does it return the "Hello World!"? – B_CooperA Nov 21 '16 at 10:59
  • @AkiraHora can you post your server config (virtual host)? I think it's not a laravel problem. – sleepless Nov 21 '16 at 11:02
0

It's your server config.

Please use /hiro/public as your document root in your vhost.

Alternatively add this to your .htaccess file:

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
sleepless
  • 1,769
  • 1
  • 22
  • 33
  • You mean like create a new apache vhost? – Akira Hora Nov 21 '16 at 11:09
  • Not necessarily. Just edit the existing vhost's `DocumentRoot`. Or, as said, you can edit the .htaccess file. The goal is to get rid of the /public in your URL. – sleepless Nov 21 '16 at 11:11
  • Yep this did it for me, I almost want to curse myself and bang my head on my table, screen and laptop. I created a vhost named hiro and accessed the app via http://hiro/ This is fixed, thanks to all who tried to help me. – Akira Hora Nov 21 '16 at 11:19