laravel 5.4 New Feature – Add eloquent whereKey method

laravel 5.4 New Feature – Add eloquent whereKey method

In this post we will give you information about laravel 5.4 New Feature – Add eloquent whereKey method. Hear we will give you detail about laravel 5.4 New Feature – Add eloquent whereKey methodAnd how to use it also give you demo for it if it is necessary.

Yesterday release Laravel 5.4 new version with new features and many upgrade. Laravel also provide documentation for Laravel 5.4 on their website. There are several update in Laravel 5.4 like in collections, mail, factory helper, Bootstrappers etc.

In this post we are going to see whereKey method in Laravel Eloquent. whereKey is very simple way to use and pretty interesting feature. laravel provide us where condition with add key(column) name and then value, But in this method you have write Key = name of column.

So i am going to give one example for whereKey() that way you can understand how it is working. So first we have on “posts” table with some dummy data like as bellow screen shot.

posts table

Ok, now we require to get only status = ‘PUBLISHED’ records. So now using whereKey() through we can make query as like bellow:

whereKey() Example



Route::get('wherekey', function () {

$posts = DB::table('posts')

->select(["id","title","status"])

->whereStatus("PUBLISHED")

->get();

dd($posts);

});

You will be found out put as like bellow:

Output:



IlluminateSupportCollection Object

(

[items:protected] => Array

(

[0] => stdClass Object

(

[id] => 21

[title] => My Sample Post

[status] => PUBLISHED

)

[1] => stdClass Object

(

[id] => 23

[title] => Latest Post

[status] => PUBLISHED

)

[2] => stdClass Object

(

[id] => 27

[title] => Yarr Post

[status] => PUBLISHED

)

)

)

I hope it can help you…

Hope this code and post will helped you for implement laravel 5.4 New Feature – Add eloquent whereKey method. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

6  +  1  =  

We accept paid advance and paid guest Posting on our Site : Contact US