I'm trying to modify my register (the Laravel 5.1 build-in register) so I can insert a record into another table.
My register:
<?php
namespace Cussion\Http\Controllers\Auth;
use Cussion\User;
use Request;
use Validator;
use Cussion\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
private $redirectTo = '/dashboard';
private $maxLoginAttempts = 3;
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:4',
'password2' => 'required|same:password',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
if (User::where('slug', '=', strtolower($data['firstname']).'.'.strtolower($data['lastname']))->exists()) {
return User::create([
'firstname' => strtolower($data['firstname']),
'lastname' => strtolower($data['lastname']),
'slug' => strtolower($data['firstname']).'.'.strtolower($data['lastname']).'.'.time(),
'email' => strtolower($data['email']),
'password' => bcrypt($data['password']),
'ip_reg' => Request::ip(),
]);
}else{
return User::create([
'firstname' => strtolower($data['firstname']),
'lastname' => strtolower($data['lastname']),
'slug' => strtolower($data['firstname']).'.'.strtolower($data['lastname']),
'email' => strtolower($data['email']),
'password' => bcrypt($data['password']),
'ip_reg' => Request::ip(),
]);
}
}
}
So here I check if a user slug exist and if so, it needs to add the time(); I acctually want to have added 1 if it is the first and 2 if second and so on. Just like you have on facebook, so maybe if someone can fix that too, would be great.
I want to insert a new record in users_images with the user_id of the just registered user.
This is what that table has of values:
id, user_id, image, created_at, updated_at
I acctually just want to have the user_id and timestamps filled in, since the rest will go automatic.
How can I do this using Laravel 5.1?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire