这是我的客户模型
protected $table = 'customers';
protected $fillable = [
'name', 'email','customer_number', 'password','customer_ph_number' //added by me
];
protected $appends = [
'account_active', 'avatar', 'points','campaign_text', 'number', 'events'
];
protected $hidden =
[
'id', 'campaign_id', 'history', 'campaign', 'events', 'password', 'remember_token', 'account', 'global_points', 'account_id', 'remote_customer_id', 'previous_remote_customer_id', 'domain', 'company', 'company_slug', 'files_dir', 'verification_code', 'token', 'login_code', 'login_code_valid_until', 'signup_ip_address', 'logins', 'last_login', 'last_login_ip_address', 'expires', 'customer_number', 'lead_source', 'lead_source_module', 'lead_status', 'lead_type', 'created_by', 'updated_by', 'created_at', 'salutation', 'first_name', 'last_name', 'job_title', 'date_of_birth', 'phone', 'mobile', 'website', 'fax', 'street1', 'street2', 'city', 'state', 'postal_code', 'country_code', 'zoom', 'lat', 'lng', 'primary_account', 'email_verified_at', 'hourly_rate', 'notes', 'additional_fields', 'settings', 'tags', 'attributes', 'meta', 'minus_sign', 'account_active', 'bank', 'bank_id', 'currency_code', 'ecode_swift', 'first_day_of_week', 'iban', 'id_number', 'id', 'media', 'shipping_city', 'shipping_country_code', 'shipping_lat', 'shipping_lng', 'shipping_postal_code', 'shipping_state', 'shipping_street1', 'shipping_street2', 'shipping_zoom', 'vat_number', 'gender', 'mobile_business', 'mobile_personal', 'phone_business', 'phone_personal', 'social'
];
protected $casts = [
'uuid' => 'uuid',
'email_verified_at' => 'datetime',
'social' => 'json',
'settings' => 'json',
'tags' => 'json',
'attributes' => 'json',
'meta' => 'json'
];
public static function getCreateForm() {
$owner = [
'tab1' => [
'text' => __('General'),
'subs' => [
'sub1' => [
'items' => [
['type' => 'text', 'column' => 'name', 'text' => __('Name '), 'validate' => 'required|max:32', 'required' => true],
['type' => 'email', 'column' => 'email', 'text' => __('E-mail address'), 'validate' => 'required|email|max:64', 'required' => true],
['type' => 'password', 'column' => 'password', 'text' => __('Password'), 'hint_edit' => __('Leave blank to keep current password'), 'validate' => 'nullable|min:8|max:32', 'validate_create' => 'required|min:8|max:32', 'required_create' => true],
// ['type' => 'text', 'column' => 'customer_number', 'text' => __('Phone Number'), 'hint_edit' => __('Please enter Your phone number here'), 'validate' => 'required|min:10|max:10', 'required'=>true],
['type' => 'text', 'column' => 'customer_ph_number', 'text' => __('Phone Number'), 'hint_edit' => __('Please enter Your phone number here'), 'validate' => 'required|min:10|max:10', 'required'=>true],
['type' => 'image', 'image' => ['thumb_width' => '140px', 'thumb_height' => '140px'], 'column' => 'avatar', 'text' => __('Avatar'), 'validate' => 'nullable', 'icon' => 'account_circle', 'class' => 'img-rounded my-3'],
['type' => 'boolean', 'default' => true, 'column' => 'active', 'text' => __('Active'), 'validate' => 'nullable']
]
]
]
]
];
$reseller = $owner;
$user = $owner;
return [
1 => $owner,
2 => $reseller,
3 => $user
];
}
以下是“customer”表模式
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id');
$table->bigInteger('account_id')->unsigned()->nullable()->index();
$table->foreign('account_id')->references('id')->on('users')->onDelete('cascade');
$table->bigInteger('campaign_id')->unsigned()->nullable()->index();
$table->foreign('campaign_id')->references('id')->on('campaigns')->onDelete('cascade');
$table->tinyInteger('role')->unsigned()->default(1);
$table->boolean('active')->default(true);
$table->string('remote_customer_id', 200)->nullable();
$table->string('previous_remote_customer_id', 200)->nullable();
$table->string('customer_number', 32)->nullable();
$table->string('name', 64)->nullable();
$table->string('email', 128)->nullable();
$table->string('verification_code', 64)->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password')->nullable();
$table->string('token')->nullable();
$table->string('login_code', 64)->nullable();
$table->timestamp('login_code_valid_until')->nullable();
$table->string('language', 5)->nullable();
$table->string('locale', 24)->nullable();
$table->char('currency_code', 3)->nullable();
$table->string('timezone', 32)->nullable();
$table->tinyInteger('first_day_of_week')->nullable();
$table->ipAddress('signup_ip_address')->nullable();
$table->integer('logins')->default(0)->unsigned();
$table->dateTime('last_login')->nullable();
$table->ipAddress('last_login_ip_address')->nullable();
$table->dateTime('expires')->nullable();
$table->string('salutation', 32)->nullable();
$table->string('first_name', 64)->nullable();
$table->string('last_name', 64)->nullable();
$table->tinyInteger('gender')->nullable();
$table->string('job_title', 64)->nullable();
$table->date('date_of_birth')->nullable();
$table->string('lead_source', 250)->nullable();
$table->string('lead_source_module', 128)->nullable();
$table->string('lead_status', 128)->nullable();
$table->string('lead_type', 128)->nullable();
$table->string('phone', 32)->nullable();
$table->string('mobile', 32)->nullable();
$table->string('website', 250)->nullable();
$table->string('fax', 32)->nullable();
$table->string('street1', 250)->nullable();
$table->string('street2', 250)->nullable();
$table->string('city', 64)->nullable();
$table->string('state', 64)->nullable();
$table->string('postal_code', 32)->nullable();
$table->char('country_code', 2)->nullable();
// Location
$table->tinyInteger('zoom')->nullable();
$table->decimal('lat', 17, 14)->nullable();
$table->decimal('lng', 18, 15)->nullable();
$table->string('company', 96)->nullable();
$table->string('shipping_street1', 250)->nullable();
$table->string('shipping_street2', 250)->nullable();
$table->string('shipping_city', 64)->nullable();
$table->string('shipping_state', 64)->nullable();
$table->string('shipping_postal_code', 32)->nullable();
$table->char('shipping_country_code', 2)->nullable();
// Shipping location
$table->tinyInteger('shipping_zoom')->nullable();
$table->decimal('shipping_lat', 17, 14)->nullable();
$table->decimal('shipping_lng', 18, 15)->nullable();
$table->string('vat_number', 250)->nullable();
$table->string('id_number', 250)->nullable();
$table->string('bank', 250)->nullable();
$table->string('bank_id', 250)->nullable();
$table->string('ecode_swift', 250)->nullable();
$table->string('iban', 250)->nullable();
$table->mediumText('notes')->nullable();
$table->json('settings')->nullable();
$table->json('tags')->nullable();
$table->json('attributes')->nullable();
$table->json('meta')->nullable();
$table->bigInteger('created_by')->unsigned()->nullable()->index();
$table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
$table->bigInteger('updated_by')->nullable()->unsigned();
$table->rememberToken();
$table->timestamps();
});
DB::statement('ALTER TABLE `customers` ADD `uuid` BINARY(16) UNIQUE NULL AFTER `id`;');
}
下面是我更新专栏时所做的操作
public function newTransaction(Request $request){
$account = app()->make('account');
$user = Customer::withoutGlobalScopes()->where('id', Auth::user('customer')->id)->where('campaign_id', $campaign->id)->firstOrFail();
$locale = request('locale', config('system.default_language'));
app()->setLocale($locale);
$previousSikka = $user->points; //For getting previous all sikka
$sending_amount = $request->sending_amount;
$remarks =$request->transaction_remarks;
$latest_sikka = (int)($sending_amount / 100);
$total_sikka = $latest_sikka + $previousSikka ;
$NPRvalue = $total_sikka / 100;
Customer::where('id', Auth::user('customer')->id)->update(array('points' => $total_sikka));
return response()->json([
'status'=>'success',
"totalSikka"=>($total_sikka),
"pointsss"=>$customers_point,
"total_sikka"=>$total_sikka
],200);
}
But it is throwing error as local.ERROR:
> SQLSTATE[42S22]: Column not found: 1054 Unknown column 'points' in
> 'field list' (SQL: update `customers` set `points` = 400,
> `customers`.`updated_at` = 2023-01-11 06:05:40 where `id` = 40)
> {"userId":40,"exception":"[object]
> (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]:
> Column not found: 1054 Unknown column 'points' in 'field list' (SQL:
> update `customers` set `points` = 400, `customers`.`updated_at` =
> 2023-01-11 06:05:40 where `id` = 40) at
> C:\\laragon\\www\\earnsikka\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:669)
> [stacktrace]
I want the points to be updated in customer table
1条答案
按热度按时间uklbhaso1#
您的问题与更新声明有关:
您正在尝试更新customers表,但它没有
points
列。另外,我在迁移中没有看到points
列,因此它似乎不存在。但是我看到你在用户中有积分!而且我认为你是在试图更新用户而不是客户。
在这种情况下,您只需更新您的用户:
因为我看到你也是用用户来获得积分的: