我在Laravel上遇到问题,无法让它登录网站上的用户。 数据库都是用预定义的用户设置的。 显示初始网页。 (不知道为什么@yield拉任何东西)
即使我在控制器中早些时候声明了类似“ auth”之类的东西,我仍然不断遇到问题。
在此方面的任何帮助将不胜感激。 我遵循了本教程,并更改了一些函数名称以匹配标准的laravel布局。 youtube.com/watch?v=OUFmvAnFclo
Controller
<?php
namespace App\Http\Controllers;
use App\Authentication;
use Illuminate\Http\Request;
use Validator;
use Auth;
class AuthController extends Controller
{
public function index()
{
return view('login.auth');
}
public function create()
{
//
}
public function store(Request $request)
{
$this->validate($request,[
'username' => 'required|username','password' => 'required|alphaNum|min:5'
]);
$user_data = array(
'username' => $request->get('username'),'password' => $request->get('password')
);
if(Auth::attempt($user_data)){
return redirect('welcome');
}
else{
return back()->with('error','Your details are incorrect');
}
}
public function show(Authentication $authentication)
{
return view('welcome');
}
public function edit(Authentication $authentication)
{
//
}
public function update(Request $request,Authentication $authentication)
{
//
}
public function destroy(Authentication $authentication)
{
Auth::logout();
return redirect('login');
}
}
auth
(查看)
@yield('heading')
@yield('login')
@yield('sign-up')
@yield('footer')
@if(isset(Auth::user()->password))
<script>window.location="/login/success";</script>
@endif
<header><h2>Already a member?<br> Sign in here</h2></header>
<div class="container">
@if ($message = Session::get('error'));
<div class="alert alert-danger alert-block">
<button type="button" class="close" data-dismiss="alert">x</button>
<strong>{{$message}}</strong>
</div>
@endif
@if(count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach($errors->all() as$error)
<li>{{$error}}</li>
@endforeach
</ul>
</div>
@endif
<form method="POST" action="{{ url('/login/store") }}">
<label for="username">username:</label>
<input type="text" id="username" name="username" placeholder="Enter username">
<label for="password">Password:</label>
<input type="text" id="password" name="password" placeholder="Enter Password">
<input type="submit" name="login" value="login">
</form>
</div>
Welcome
(查看)
@if(isset(Auth::user()->password))
<div class="alert alert-danger success-block">
<strong>Welcome {{ Auth::user() ->password }}</strong>
<a href=" {{url('logout')}}">Logout</a>
</div>
else
<script>window.location="/login";</script>
@endif
Web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/login','AuthController@index');
Route::post('/login/store','AuthController@store');
Route::get('login/success','AuthController@show');
Route::get('login/logout','AuthController@destroy');
感谢您的光临, 本