How to convert SQL with CAST function to Eloquent
Assuming you have set up wp_posts
and wp_postmeta
modal as said in this tutorial then below query will do the thing for you.
$dp = DB::getTablePrefix();$order_by = "CAST(" . $dp . "postmeta.meta_value AS unsigned) DESC";BlogPost::with('postmetas') ->where('posts.post_date', '>', '2017-04-20 23:59:59') ->where('postmeta.meta_key', 'views') ->orderByRaw($order_by) ->limit(10) ->get();
Hope this helps!