0

Iam usin mysql 5.7,laravel5.2 and php 5.6.17 in my application..

I created a 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();
        });
    }

I created a model for it..

class AdminLoginHistory extends Model
{

    protected $table = 'admin_login_history';

    protected $fillable = ['file_path', 'url', 'user_id', 'client_details'];

    protected $casts = ['client_details' => 'json'];
}

Iam inserting a array of data of client_details which is converted to json in my model.

now when retrieving the data from the table iam getting error

$loginhistory = AdminLoginHistory::where('user_id', $id)->orderBy('created_at', 'desc')->take(3)->get();

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)
Veerendra Borra
  • 1,286
  • 14
  • 24

2 Answers2

0

This might be similar to this post. JSON data is still relative new in MySQL so I imagine it'll take a little while before things are rock solid.

Community
  • 1
  • 1
JasonJensenDev
  • 2,377
  • 21
  • 30
0

"As of MySQL 5.7.8, MySQL supports a native JSON data type... " So check if you have the correct versión of mysql (5.7.8 or newer).

Mysql 5.7.8 JSON data type, doc

echinelli
  • 51
  • 3