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)

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.