与主题一样,今天我正在使用新的Laravel 5.6创建一个Login面板。我只使用了Laravel面板和用户模型,并创建了UserController:
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
// Auto loading middleware
public function __construct()
{
$this->middleware('auth');
}
public function add()
{
return view('User.add');
}
public function save(Request $request)
{
// Metoda 1
User::create($request->all());
}
public function login()
{
return view('welcome');
}
public function register()
{
return view('auth.register');
}
}
Laravel的观点"登录"由我重构:
<main>
<section class="well-md well-md--inset-3 marker relative">
<div class="container-fluid container-inset">
@if(!empty($msg))
{{ $msg }}
@endif
<h2 class="text-center text-md-left">Logowanie</h2>
<form class='rd-mailform' method="post" action="{{ route('login') }}">
{{ csrf_field() }}
@csrf
<fieldset>
<div class="row flow-offset">
<div class="col-sm-12">
<label data-add-placeholder="">
<input type="text"
name="email"
class="{{$errors->has('email') ? ' is-invalid' : ''}}" value="{{ old('email')}}"
required autofocus
placeholder="Twój email"
data-constraints="@NotEmpty @Email"/>
</label>
<label data-add-placeholder="">
<input type="password"
name="haslo"
class="{{$errors->has('haslo') ? ' is-invalid' : ''}}" value="{{ old('haslo')}}"
required autofocus
placeholder="Hasło"
data-constraints="@NotEmpty @Password"/>
</label>
<label>
<div class="remember">Zapamiętaj</div>
<div class="justify-checkbox">
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}/>
</div>
</label>
</div>
<div class="mfControls text-center text-lg-right">
<button class="btn btn-default btn-md uppercase " type="submit">Wyślij</button>
</div>
<div class="mfInfo"></div>
</div>
</fieldset>
</form>
</div>
</section>
</main>
这是我的路线:
// Not protected sites
/////////////////////////////////////////////////////////////////////////
Route::get('/' , 'HomeController@welcome');
Route::get('/onas' , [
'uses' => 'HomeController@onas',
'as' => 'Home@onas'
]);
Route::get('/cennik' , [
'uses' => 'HomeController@cennik',
'as' => 'Home@cennik'
]);
Route::get('/samochody' , [
'uses' => 'HomeController@samochody',
'as' => 'Home@samochody'
]);
Route::get('/uslugi' , [
'uses' => 'HomeController@uslugi',
'as' => 'Home@uslugi'
]);
Route::get('/konto' , [
'uses' => 'HomeController@konto',
'as' => 'Home@konto'
]);
Route::get('/kontakt' , [
'uses' => 'MailController@kontakt',
'as' => 'Mail@kontakt'
]);
Route::post('/kontakt' , 'MailController@wyslij');
// Protected routes
////////////////////////////////////////////////////////////////////////////
Route::group(['middleware' => 'auth'], function()
{
Route::get('/add' , 'UserController@add');
Route::post('/save' , [ // Tablica taka posiada wiele różnych kluczy
'uses' => 'UserController@save' ,
'as' => 'User.Save'
]);
Route::get('/show/{user}' , [
'uses' => 'UserController@show' ,
'as' => 'User.Show'
]);
Route::get('/login' , 'UserController@login');
Route::get('/register' , 'UserController@register');
数据库迁移:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('imie');
$table->string('nazwisko');
$table->string('ulica');
$table->string('numer');
$table->string('kod-pocztowy');
$table->string('miasto');
$table->string('telefon');
$table->string('nip');
$table->string('email')->unique();
$table->string('haslo');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
我的问题是,为什么我无法登录用户?数据库列是匹配的。请帮帮我们!