M
M
MrChen2016-07-23 01:45:34
Laravel
MrChen, 2016-07-23 01:45:34

Why doesn't registration on Laravel work?

Hello! Guys, everything seems to be written correctly in the controller, but for some reason it does not redirect by link, although it adds to the database ... Is it correct to authorize immediately after registration?
PS My controller is shit code?
Controller code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use Illuminate\Support\Facades\Redirect;

use Illuminate\Support\Facades\Validator;

use Illuminate\Support\Facades\Input;

use Illuminate\Support\Facades\Hash;

use DB;

use View;

use App\User;

use Auth;

class UsersController extends Controller
{
  public function getRegister() {
    return View::make('user/register');
  }

  public function postRegister(Request $request)
  {
    $this->validate($request, [
          'login' => 'unique:users|min:6|max:15',
          'email' => 'email|unique:users',
          'password' => 'min:6|max:20|same:r_password',
          'r_password' => 'min:6|max:20',
          'about' => 'min:20|max:200'
    ]);

    $user = User::create([
      'login' => $request->input('login'),
      'email' => $request->input('email'),
      'password' => Hash::make($request->input('password')),
      'about' => $request->input('about'),
    ]);

    $user_auth = array(
      'login' => $request->input('login'),
      'password' => Hash::make($request->input('password'))
    );

    if(Auth::attempt($user_auth) && !empty($user->id)) {
      return Redirect::to('user/' . $user->id);
    } else {
      return Redirect::back();
    }
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question