-
Please, reformat your code like described here https://help.github.com/articles/creating-and-highlighting-code-blocks/
-
You would use Eloquent Models and set up relationships. Then everything will work as a charm.
// User.php
public function lawyers() {
return $this->hasMany(Lawyer::class);
// or hasOne? whatever relation you have got there
}
// Lawyer.php
public function user() {
return $this->belongsTo(User::class);
}
// License.php
public function lawyer() {
return $this->belongsTo(Lawyer::class);
}
// UsersController.php
public function registerLawyer(Request $request){
$user_attributes = $request->only([
'firstname',
'lastname',
// all the attributes you need for the user
]);
// Or you would even like to validate the attributes
//$user_attributes = $request->validate(array_or_rules);
$user = User::create($user_attributes)
$lawyer_attributes = $request->only([
'practices',
]);
// Or you would even like to validate the attributes
//$lawyer_attributes = $request->validate(array_or_rules);
$lawyer = $user->lawyers()->save(new Lawyer($lawyer_attributes));
$license_attributes = $request->only([
'licenseno',
'institution',
]);
// Or you would even like to validate the attributes
//$license_attributes = $request->validate(array_or_rules);
$license = $lawyer ->licenses()->save(new License($license_attributes));
return redirect('welcome');
}
Read about validation https://laravel.com/docs/5.6/validation, Eloquent https://laravel.com/docs/5.6/eloquent