0

My code is again troubling me. Now I tried to route it to a dashboard but caused an error.

User controller:

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
//use Illuminate\Support\Facades\Flash;
use InvalidConfirmationCodeException;
use Flash;
//use Mail;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class UserController extends Controller
{
public function getDashboard()


   {

     return view('dashboard');
   }


 public function postSignUp(Request $request)
 {

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

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

Auth::login('$user');

$user->save();

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

public function postSignIn(Request $request)
 {

if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']]))  {

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

       return redirect()->back();

 }
}

Dashboard.blade.php:

<h1>Dashboard<h1>

Routes\web.php:

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

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


            ]);

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


            ]);

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

Welcome.blade.php:

@extends('layouts.master')
@section('title')
Welcome!!
@endsection
@section('content')
<div class="row">
    <div class="col-md-6">
        <h2>Sign Up</h2>
          <!--<form action="{{route('signup')}}" method="POST">  -->
          <form action="/signup" method="POST">
            <div class="form-group">
                <label for="email">Your E-Mail</label>
                <input class="form-control" type="text" name="email" id="email">
            </div>  
            <div class="form-group">
                <label for="name">Name</label>
                <input class="form-control" type="text" name="name" id="name">
            </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 class="col-md-6">
        <h2>Sign In</h2>
        <form action="#" method="POST">
            <div class="form-group">
                <label for="email">Your E-Mail</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>

</div>
@endsection

please tell me the solution and why am I getting this error again and again? I changed {{route('signup')}} with /signup .. it worked at first.. but again it's not working. I am unable to understand where am i doing wrong.

3 Answers3

0

I am guessing you are using Laravel framework. You need to write your routes in app/Http/routes.php file which currently I believe are in web.php you can check this link for further information.

Also, about your middleware web configure it properly according to the steps given here

I hope this helps.

Akshay Gohil
  • 370
  • 2
  • 10
0

1) change

Illuminate\Support\Facades\Auth;

to

Use Auth;

2) Check with the routes you must be referencing post method with get request.

 Route::post('signup','UserController@postSignUp');

and form should be

<form action="signup" method="post">
Aniket Karne
  • 325
  • 3
  • 14
-1

Check both the links. As this the framework error as it seems from outside. Check the Form METHOD= " " ; also check the exception method.

Link 1

Link 2

Community
  • 1
  • 1