veerendra
3 years ago
329
11
Eloquent

Json column problem with Mysql5.7 and laravel5.2

Posted 3 years ago by veerendra

How to retrieve json column data from the json column type in mysql 5.7?

Here is my Eloquent model and migration

class AdminLoginHistory extends Model
{
    protected $table = 'admin_login_history';
    protected $fillable = ['file_path', 'url', 'user_id', 'client_details'];
    protected $casts = ['client_details' => 'json'];
}

Database Migration Table
  public function up()
    {
        Schema::create('admin_login_history', function (Blueprint $table) {
            $table->increments('id');
            $table->string('url');
            $table->json('client_details');
            $table->integer('user_id')->nullable();
            $table->timestamps();
        });
    }

Iam converting  array of client_details  to json and inserting in to data base.

Now,when trying to retrieve the data iam getting error

File Path: /home/storage/elivio/InvizoAdmin/vendor/laravel/framework/src/Illuminate/Database/Connection.php
Error Code: HY000, 
 Line Number: 669
Message: SQLSTATE[HY000]: General error: 2036 (SQL: select * from `admin_login_history` where `user_id` = 1 order by `created_at` desc limit 3)

Iam using laravel 5.2,php-5.6.17 and MySQL 5.7.

Please sign in or create an account to participate in this conversation.