我的代码再次困扰着我。现在我尝试将其路由到仪表板但导致错误。
用户控制器:
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>
路线\ 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
请告诉我解决方案,为什么我一次又一次地收到此错误?我用/ signup更改了{{route(&#39;注册&#39;)}} ..它最初工作了......但是它再次无效。我无法理解我在哪里做错了。
答案 0 :(得分:0)
我猜你正在使用Laravel框架。
您需要在app/Http/routes.php
文件中编写您的路线,目前我认为这些路线位于web.php
,您可以查看this link以获取更多信息。
此外,关于您的中间件web
根据给定的here
我希望这会有所帮助。
答案 1 :(得分:0)
1)改变
Illuminate\Support\Facades\Auth;
到
Use Auth;
2)检查您必须使用get请求引用post方法的路由。
Route::post('signup','UserController@postSignUp');
和表格应该是
<form action="signup" method="post">
答案 2 :(得分:-1)