isn't it the current user?
Its the controller code we need to see
Hi all. I'm still working on my Laravel 8 ecommerce project. I arleady have a user model with a user table for email and password. But now I need to give registered users the ability to create a shipping address to shipping rates to them. I created a user address table, and in the UserAddress model, tried to build a relationship with the User's id in the user table, but when the user submits the address form, I keep getting a General error: 1364 Field 'member_id' doesn't have a default value (SQL: insert into user_addresses error.
Here is my code in the user address model
class UserAddress extends Model { use HasFactory;
protected $guarded = [];
public function user(){
return $this->belongsTo(User::class,'member_id','id'); }
Here is the code for the user address migration
public function up()
{
Schema::create('user_addresses', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('member_id');
$table->foreign('member_id')->references('id')->on('users')->onDelete('cascade');;
$table->string('name');
$table->string('shipping_last_name');
$table->string('company')->nullable();
$table->string('city');
$table->string('street1');
$table->string('street2')->nullable();
$table->string('state');
$table->string('country');
$table->string('phone');
$table->string('email');
$table->integer('zip');
$table->text('notes')->nullable();
$table->integer('address_status')->default(0);
$table->timestamps();
});
}
Lastly, here is the code for my address form in the user dashboard
@csrf
<div class="checkbox-form">
<h3>Billing Details</h3>
<div class="row">
<div class="col-md-12">
<div class="country-select clearfix">
<label>Country <span class="required">*</span></label>
<input placeholder="Country" name="country" type="text">
</div>
</div>
<div class="col-md-6">
<div class="checkout-form-list">
<label>First Name <span class="required">*</span></label>
<input placeholder="First Name" name="name" type="text">
</div>
</div>
<div class="col-md-6">
<div class="checkout-form-list">
<label>Last Name <span class="required">*</span></label>
<input placeholder="Last Name" name="shipping_last_name" type="text">
</div>
</div>
<div class="col-md-12">
<div class="checkout-form-list">
<label>Shipping Email</label>
<input placeholder="Email" name="email" type="email">
</div>
</div>
<div class="col-md-12">
<div class="checkout-form-list">
<label>Company Name</label>
<input placeholder="" name="company" type="text">
</div>
</div>
<div class="col-md-12">
<div class="checkout-form-list">
<label>Address <span class="required">*</span></label>
<input placeholder="Street address" name="street1" type="text">
</div>
</div>
<div class="col-md-12">
<div class="checkout-form-list">
<input placeholder="Apartment, suite, unit etc. (optional)" name ="street2" type="text">
</div>
</div>
<div class="col-md-12">
<div class="checkout-form-list">
<label>Town / City <span class="required">*</span></label>
<input type="text" name="city">
</div>
</div>
<div class="col-md-6">
<div class="checkout-form-list">
<label>State / County <span class="required">*</span></label>
<input placeholder="" name="state" type="text">
</div>
</div>
<div class="col-md-6">
<div class="checkout-form-list">
<label>Postcode / Zip <span class="required">*</span></label>
<input placeholder="" name="zip" type="text">
</div>
</div>
</div>
<div class="col-md-6">
<div class="checkout-form-list">
<label>Phone <span class="required">*</span></label>
<input type="text" name="phone">
</div>
</div>
<div class="order-button-payment">
<input value="Submit Address" type="submit">
</div>
</form>
Am I missing member_id input in the form? If so, how do I include it.
Thanks
Please or to participate in this conversation.