0
votes

In Laravel-8 application, I am tring to use this function:

public static function addToLog($subject, $logType=null, $subjectHint=null)
{
    $log = [];
    $log['subject'] = $subject;
    $log['log_type'] = $logType;
    $log['subject_hint'] = $subjectHint;
    $log['log_url'] = Request::fullUrl();
    $log['log_method'] = Request::method();
    $log['ip_address'] = Request::ip();
    $log['agent'] = Request::header('user-agent');
    $log['user_id'] = auth()->check() ? auth()->user()->id : 1;
    LogActivityModel::create($log);
}

But I got this error:

[2021-05-19 13:25:55] local.ERROR: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ip_address' in 'field list' in C:\xampp\htdocs\myapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:465

But ip_address column exists.

Here is my migration:

public function up()
{
    Schema::create('user_log_activities', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->nullable()->unsigned();
        $table->string('log_url', 300)->nullable();
        $table->string('log_method', 20)->nullable();
        $table->string('log_type', 50)->nullable();
        $table->string('subject', 200)->nullable();
        $table->string('subject_hint', 20)->nullable();
        $table->string('id_address', 64)->nullable();
        $table->string('agent', 300)->nullable();
        $table->timestamps();
    });
}

How do I get it resolve?

Thanks

1
What's your migration? - brombeer
@brombeer - I have added the migration - user11352561
please add LogActivityModel as well - OMR
you column in Migration called "id_address" while in controller code called "ip_address " you should united them! - OMR
is their column exist in your model fillable property? - Yudiz Solutions

1 Answers

0
votes

You're given a wrong column name in your migration change it to ip_address instead of id_address. Something like this.

 $table->string('ip_address', 64)->nullable();