From 0dd47a2b7a32160c9a229ca3c7467490942b596a Mon Sep 17 00:00:00 2001 From: basemkhirat Date: Sun, 23 Jul 2017 15:08:16 +0000 Subject: [PATCH] fix readme file --- readme.md | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/readme.md b/readme.md index 95ce107..2743f54 100755 --- a/readme.md +++ b/readme.md @@ -337,7 +337,7 @@ Have a look at [laravel Scout documentation](https://laravel.com/docs/5.4/scout# ## Elasticsearch data model Each index type has a corresponding "Model" which is used to interact with that type. -Models allow you to query for data in your types or indices, as well as insert new records into the type. +Models allow you to query for data in your types or indices, as well as insert new documents into the type. ##### Basic usage @@ -356,7 +356,7 @@ class Post extends Model } ``` -The above example will use the default connection and default index in `es.php` but you can override that both in the next example. +The above example will use the default connection and default index in `es.php`. You can override both in the next example. ```php save(); ##### Mass Updates -Updates can also be performed against any number of models that match a given query. In this example, all flights that are active and have a destination of San Diego will be marked as delayed: +Updates can also be performed against any number of models that match a given query. In this example, all posts that are active and have a views lower than 5 will be marked as archived: ```php App\post::where('active', 1) - ->where('destination', 'San Diego') - ->update(['delayed' => 1]); + ->where('views', "<", 5) + ->update(['archived' => 1]); ``` ##### Deleting Models -To delete a model, call the delete method on a model instance: +To delete a model, call the `delete()` method on a model instance: ```php $post = App\Post::find(1); @@ -490,7 +490,7 @@ $post->delete(); ##### Deleting Models By Query -Of course, you may also run a delete statement on a set of models. In this example, we will delete all flights that are marked as inactive. Like mass updates, mass deletes will not fire any model events for the models that are deleted: +Of course, you may also run a delete statement on a set of models. In this example, we will delete all posts that are marked as inactive. Like mass updates: ```php $deletedDocuments = App\Post::where('active', 0)->delete(); @@ -498,9 +498,9 @@ $deletedDocuments = App\Post::where('active', 0)->delete(); ##### Query Scopes -Local scopes allow you to define common sets of constraints that you may easily re-use throughout your application. For example, you may need to frequently retrieve all users that are considered "popular". To define a scope, simply prefix an Eloquent model method with scope. +Scopes allow you to define common sets of constraints that you may easily re-use throughout your application. For example, you may need to frequently retrieve all posts that are considered "popular". To define a scope, simply prefix an Eloquent model method with scope. -Scopes should always return a query builder instance. +Scopes should always return a Query instance. ```php title; ``` +Occasionally, you may need to add array attributes that do not have a corresponding field in your index. To do so, simply define an accessor for the value: + +```php +public function getIsPublishedAttribute() +{ + return $this->attributes['status'] == 1; +} +``` + +Once you have created the accessor, just add the value to the `appends` property on the model: + +```php +protected $appends = ['is_published']; +``` + +Once the attribute has been added to the appends list, it will be included in model's array. + ###### Defining A Mutator To define a mutator, define a `setFooAttribute` method on your model where `Foo` is the "studly" cased name of the column you wish to access. So, again, let's define a mutator for the `title` attribute. This mutator will be automatically called when we attempt to set the value of the `title`attribute on the model: