I'm trying to ask everyone here how I would handle adding a row to the profiles table once a user is stored in the database. Right now the only thing that is happening is a new row is created in the users table which is what is expected but I also want to take that id of the user and add a new row and put it as the user_id field in the user_profiles table.
/**
* Save a new user.
*
* @param UserRequest $request
* TODO: Find a way to add a profile to a user once the user is saved.
*
* @return Response
*/
public function store(UserRequest $request)
{
$user = $this->userRepository->create($request->all());
return redirect('users');
}
Create Method is inside of the base repository known as EloquentRepository from which the userRepository extends from.
/**
* Create a new modal instance in the database.
*
* @param array $data Attributes to be saved for the user.
*
* @return mixed
*/
public function create(array $data)
{
return $this->model->create($data);
}
EDIT:
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('email')->unique();
$table->string('password', 60);
$table->integer('user_role_id')->unsigned();
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
$table->foreign('user_role_id')->references('id')->on('user_roles');
});
Schema::create('user_profiles', function(Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->text('bio')->nullable();
$table->string('address')->nullable();
$table->string('city')->nullable();
$table->string('state')->nullable();
$table->integer('postcode')->nullable();
$table->string('country')->nullable();
$table->string('phone')->nullable();
$table->timestamp('birthday')->nullable();
$table->string('facebook_username')->unique()->nullable();
$table->string('twitter_username')->unique()->nullable();
$table->string('google_plus_username')->unique()->nullable();
$table->string('behance_username')->unique()->nullable();
$table->string('pinterest_username')->unique()->nullable();
$table->string('linkedin_username')->unique()->nullable();
$table->string('github_username')->unique()->nullable();
$table->string('youtube_username')->unique()->nullable();
$table->string('instagram_username')->unique()->nullable();
$table->string('external_link')->unique()->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('user_id')->references('id')->on('users');
});