array datatype from database to eloquent laravel

Solution:

You can not use custom/raw select using select method, but you can use selectRaw method like below:

DB::Table('tableinfo')
->select('id', 'name')
->selectRaw('subject[array_length(subject, 1)] as last_subject')
->get();

above code will generate query like below:

select "id", "name", subject[array_length(subject, 1)] as last_subject from "tableinfo"