Как правильно сделать авторизацию в laravel 5.5?

Как правильно сделать авторизацию в laravel 5.5?
Вот что я делаю:
public function register(Request $request)
{
	if ($request->isMethod('post'))
	{
		$email = Input::get('email');
		$password = Input::get('password');
		$exist = User::where('email', $email)->get();
		if ($exist->isEmpty())
		{
			$user = new User;
			$user->email = $email;
			$user->password_hash = Hash::make($password);
			date_default_timezone_set('Asia/Krasnoyarsk');
			$user->created_at = date('Y-m-d H:i:s');
			$user->auth = md5(date('Y-m-d H:i:s') . 'salt');
			$user->money = 600;
			$user->save();
			$auth = Auth::attempt(['email' => $email, 'password' => $password]);
			var_dump($auth);
		} else
		{
			return view('register', ['error' => 'Такой email уже зарегистрирован!']);
		}
	} else
	{
		return view('register');
	}
}

Модель User:
<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;

class User extends Authenticatable
{
    protected $table = 'users';
	public $timestamps = false;
}

Строка Auth::attempt(['email' => $email, 'password' => $password]); возвращает всегда false.
Наверное что то неправильно в конфиге, но я не знаю что именно.
Конфиг:
<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    |
    | This option controls the default authentication "guard" and password
    | reset options for your application. You may change these defaults
    | as required, but they're a perfect start for most applications.
    |
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session", "token"
    |
    */

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    |
    | You may specify multiple password reset configurations if you have more
    | than one user table or model in the application and you want to have
    | separate password reset settings based on the specific user types.
    |
    | The expire time is the number of minutes that the reset token should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

Миграция:
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class Users extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('email')->unique();
            $table->string('password_hash', 60);
			$table->string('created_at', 19);
			$table->string('auth', 32);
			$table->string('remember_token', 100)->nullable();
			$table->string('confirmed_at', 19)->nullable();
			$table->integer('money')->nullable();
			$table->string('name')->nullable();
			$table->string('fname')->nullable();
			$table->string('nick')->nullable();
			$table->string('last_visit', 19)->nullable();
			$table->integer('avatar')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
  • Вопрос задан
  • 311 просмотров
Решения вопроса 1
kvonosan
@kvonosan Автор вопроса
Надо мне было просто.
Нашел решение, может кому пригодится.
https://stackoverflow.com/questions/26073309/how-t...

Суть в том что если у вас поле с паролем называется по другому нужно добавить в файл User.php функцию
public function getAuthPassword()
{
	return $this->password_hash;
}

Функция изменена на мой пример. Удачи!
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Sanasol
@Sanasol Куратор тега Laravel
нельзя просто так взять и загуглить ошибку
Там же всё из коробки работает, что вы пытаетесь еще сделать?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы