lundi 29 mai 2017

Laravel: NotFoundHttpException in RouteCollection.php

I tried to set up a route protection in Laravel and got the following error message:

NotFoundHttpException in RouteCollection.php line 179:

in RouteCollection.php line 179
at RouteCollection->match(object(Request)) in Router.php line 533
at Router->findRoute(object(Request)) in Router.php line 512
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{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 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
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 53

What am I doing wrong or where does the error come from? Yesterday everything worked well..

My web.php

Route::get('/', function () {
return view('welcome');
})->name('home');

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

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

Route::get('/dashboard', [
  'uses' => 'UserController@getDashboard',
  'as' => 'dashboard',
  'middleware' => 'auth'  
]);

My UserController.php:

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class UserController extends Controller{


public function getDashboard(){
  return view('dashboard');
}

public function postSignUp(Request $request){

  $this->validate($request, [
    'email' => 'required|email|unique:users',
    'name' => 'required|max:120',
    'password' => 'required|min:4'
  ]);

  $email = $request['email'];
  $name = $request['name'];
  $password = bcrypt($request['password']); 

  // Create a user
  $user = new User();

  $user->email = $email;
  $user->name = $name;
  $user->password = $password;

  $user->save();

  Auth::login($user); // Pass the created user for auto login

  return redirect()->route('dashboard');

}

public function postSignIn(Request $request){

  $this->validate($request, [
    'email' => 'required|email',
    'password' => 'required'
  ]); 

  if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
      return redirect()->route('dashboard');
  }
  return redirect()->back();
}

}

My User.php:

<?php

namespace App;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;

class User extends Model implements Authenticatable
{
    use \Illuminate\Auth\Authenticatable;
}

My RedirectIfAuthenticated.php:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect()->route('home');
        }

        return $next($request);
    }
}

my welcome.blade.php:

@extends('layouts.master')

@section('title')
  Welcome!
@endsection

@section('content')
  @if(count($errors) > 0)
  <div class="row">
    <div class="col-sm-4 col-md-offset-4">
      <ul>
          @foreach($errors->all() as $error)
            <li></li>
          @endforeach
      </ul>
    </div>
  </div>
  @endif
  <div class="row">
    <div class="col-sm-6">
      <h3>Sign Up</h3>
      <form class="" action="" method="post">
        <div class="form-group  ">
          <label for="name">Your Name</label>
          <input class="form-control" type="text" name="name" id="name" value="">
        </div>
        <div class="form-group  ">
          <label for="email">Your E-Mail</label>
          <input class="form-control" type="text" name="email" id="email" value="">
        </div>
        <div class="form-group  ">
          <label for="password">Your Password</label>
          <input class="form-control" type="password" name="password" id="password" value="">
        </div>
        <button type="submit" class="btn btn-primary" name="button">Submit</button>
        <input type="hidden" name="_token" value=""> 
      </form>
    </div>
    <div class="col-sm-6">
      <h3>Sign In</h3>
      <form class="" action="" method="post">
        <div class="form-group  ">
          <label for="email">Your E-Mail</label>
          <input class="form-control" type="text" name="email" id="email" value="">
        </div>
        <div class="form-group  ">
          <label for="password">Your Password</label>
          <input class="form-control" type="password" name="password" id="password" value="">
        </div>
        <button type="submit" class="btn btn-primary" name="button">Submit</button>
        <input type="hidden" name="_token" value=""> 
      </form>
    </div>
  </div>
@endsection

I use XMAPP and work on the localhost:81 because the port 80 was already taken.

Hope you can help me..



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rNwCTy
via IFTTT

Aucun commentaire:

Enregistrer un commentaire