Eloquent Model Query
<?php Post::query() ->whereNotIn('id', [1, 2, 3]) ->take(10) ->get(); // The query above will get the post with an id of 4, 5, 6 to 13
<?php Post::query() ->whereNotIn('slug', ['hello', 'world']) ->take(10) ->get(); // The query above will get 10 posts but will exclude the one that hs 'hello' and 'world' as slug
Using DB Facade
You can also use DB facade and the way to write it is like below.
<?php DB::table('posts') ->whereNotIn('id', [1, 2, 3]) ->take(10) ->get(); // The query above will get the post with an id of 4, 5, 6 to 13
Leave a reply