{"id":6735,"date":"2021-04-14T15:33:22","date_gmt":"2021-04-14T10:03:22","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=6735"},"modified":"2023-01-20T18:55:05","modified_gmt":"2023-01-20T13:25:05","slug":"laravel-eloquent","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/","title":{"rendered":"Laravel Eloquent"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The Eloquent ORM included with Laravel gives a wonderful, basic ActiveRecord usage for working along with your database. With eloquent, each table in the database corporate a comparing \u201c<\/span><i><span style=\"font-weight: 400;\">Model\u201d <\/span><\/i><span style=\"font-weight: 400;\">that does utilize to connect with that table.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The model permits you to insert, update and delete the records from the table to recover or fetch records from the table. They give the advantage to perform common database operations without encoding lengthy SQL queries. Eloquent provides no need to write SQL queries and all work can be done by defining tables and the relationship between those tables<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><b>#Generating Model Class:<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">To create an Eloquent model, use the <\/span><i><span style=\"font-weight: 400;\">make: model<\/span><\/i><span style=\"font-weight: 400;\"> Artisan command:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>PHP artisan make: model Users<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Models generated by the make: model command are going to be placed within the <\/span><i><span style=\"font-weight: 400;\">app\/module<\/span><\/i><span style=\"font-weight: 400;\"> directory. An example of Users model is given below:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>&lt;?php\u00a0<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>namespace App;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>use IlluminateDatabaseEloquentModel;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>class Users extends Model {<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>#code<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>}<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">If you&#8217;d wish to generate a database migration once you generate the model, you may use the <\/span><i><span style=\"font-weight: 400;\">&#8211;migration <\/span><\/i><span style=\"font-weight: 400;\">or <\/span><i><span style=\"font-weight: 400;\">-m <\/span><\/i><span style=\"font-weight: 400;\">command. When a model is generated, use the artisan command to generate a database migration.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>php artisan make: model \u2013migration<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><b>Eloquent Model Explanation:<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">You may generate varied alternative forms of classes once generating a model, like factories, seeders, and controllers. Additionally, these choices are also combined to make multiple classes at once<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong># to generate a model and a UsersFactory class&#8230;.<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>php artisan make: model Users &#8211;factory<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>or<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>php artisan make:model Users -f<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong># to generate a model and a UsersSeeders class&#8230;.<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>php artisan make: model Users\u00a0 &#8211;seed<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>or<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>php artisan make: model Users -s<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>#\u00a0 to generate a model and a UsersController class..<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>php artisan make: model Users &#8211;controller<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>or<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>PHP artisan make: model Users -c<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol>\n<li><b>Table name :<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">By convention, the plural name of the class is going to be used as the table name by default. So, eloquent can assume the Users model stores records within the <\/span><i><span style=\"font-weight: 400;\">user&#8217;s<\/span><\/i><span style=\"font-weight: 400;\"> table. And to define a model\u2019s table name manually use <\/span><i><span style=\"font-weight: 400;\">table <\/span><\/i><span style=\"font-weight: 400;\">property on the model.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>&lt;?php\u00a0namespace App;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>use IlluminateDatabaseEloquentModel;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>class Users extends Model {<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>protected $table =\u00a0 \u2018all_users\u2019;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>}<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"2\">\n<li><b>Primary Keys :<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Eloquent also will assume that each model\u2019s corresponding table has a primary key column \u201c<\/span><i><span style=\"font-weight: 400;\">id\u201d. <\/span><\/i><span style=\"font-weight: 400;\">\u00a0If needed, you can define a different column as the primary key using the <\/span><i><span style=\"font-weight: 400;\">$primaryKey <\/span><\/i><span style=\"font-weight: 400;\">property on your model.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>&lt;?php\u00a0namespace App;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>use IlluminateDatabaseEloquentModel;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>class Users extends Model {<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>protected $primaryKey =\u00a0 \u2018userid\u2019;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>}<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"3\">\n<li><b>Timestamps :<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Eloquent automatically sets values of <\/span><i><span style=\"font-weight: 400;\">created_at <\/span><\/i><span style=\"font-weight: 400;\">\u00a0and <\/span><i><span style=\"font-weight: 400;\">updated_at <\/span><\/i><span style=\"font-weight: 400;\">columns whenever models are created and updated. If you do not need these columns to manage automatically, use <\/span><i><span style=\"font-weight: 400;\">$timestamps <\/span><\/i><span style=\"font-weight: 400;\">\u00a0property on your model with a <\/span><i><span style=\"font-weight: 400;\">false <\/span><\/i><span style=\"font-weight: 400;\">value.<\/span><i><span style=\"font-weight: 400;\">\u00a0<\/span><\/i><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>&lt;?php\u00a0namespace App;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>use IlluminateDatabaseEloquentModel;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>class Users extends Model {<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>protected $timestamps =\u00a0 false;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>}<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><b>CRUD with Eloquent<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">CRUD stands for <\/span><i><span style=\"font-weight: 400;\">Create<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">\u00a0Read<\/span><\/i><span style=\"font-weight: 400;\">,<\/span><i><span style=\"font-weight: 400;\"> Update <\/span><\/i><span style=\"font-weight: 400;\">and<\/span><i><span style=\"font-weight: 400;\">\u00a0 Delete. <\/span><\/i><span style=\"font-weight: 400;\">It makes work easier for developers to work with multiple databases.<\/span><\/p>\n<h3><b># to create records:<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">:: create method is used to insert a new record in table.<\/span><\/p>\n<table style=\"height: 160px;\" width=\"629\">\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>user_record::create(array(\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2018name\u2019 =&gt; \u2018Jane\u2019,<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2018gender\u2019 =&gt; \u2018female\u2019,<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2018rank\u2019 =&gt;5<\/strong><strong>));<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Methods like save(), firstOrCreate() or firstOrNew() are also the options to create a new record.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong># using save() method$user = new Users;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>$user-&gt;name =&gt; \u2018John;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>$user-&gt;gender =&gt; \u2018male;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>$user-&gt;rank\u00a0 = 1;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>$user-&gt;save();<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>#\u00a0 to get user by name or create if doesn\u2019t exist&#8230;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>$user_record:: firstOrCreate ([<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2018name\u2019 =&gt; \u2018Jane\u2019,<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>]);<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>#\u00a0 to get used by name or create if doesn\u2019t exist with more attributes&#8230;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>$user_record:: firstOrNew (<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0[ \u2018name\u2019 =&gt; \u2018John\u2019],<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0[ \u2018gender =&gt; \u2018male\u2019, \u2018rank\u2019 =&gt;2],);\u00a0<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b># to retrieve records:<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Eloquent makes it easy and manageable t retrieve records from the database. To create :<\/span><i><span style=\"font-weight: 400;\">where <\/span><\/i><span style=\"font-weight: 400;\">statement use following methods:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>all():<\/strong> it returns all records from table.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>$usersList = Users::all();<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\"><strong>get():<\/strong> it returns an array of records.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>$female-users = Users::where(\u2018gender\u2019, \u2019=\u2019 , \u2019female\u2019)-&gt;get();<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\"><strong>first():<\/strong> it returns only one record from table.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>$female-users = Users::where(\u2018gender\u2019, \u2019=\u2019 , \u2019female\u2019)-&gt;first();<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\"><strong>find():<\/strong> this method find record based on specific attribute.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>$getusers = Users:: find(1);<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b># to update records:<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Eloquent makes it easier to update records. Updating a record includes two processes. The first is retrieving a record and the second is t set any attribute you want to update. And by calling the save() method you can update record in the database\u00a0\u00a0<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>$updateUser = Users::where(\u2018name\u2019, \u2018=\u2019, \u2018John\u2019)-&gt;first();$updateUser-&gt;rank\u00a0 = 1;<\/strong><\/span><\/p>\n<p><span style=\"color: #333399;\"><strong>$updateUser-&gt;save();<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b># to delete records:<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Eloquent provides an easy way to delete records. To achieve this there are two methods:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">delete(): In this method, we retrieve the model before calling the delete method.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>$user = Users::find(1);$user-&gt;delete();<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\"><strong>destroy() :<\/strong> This method will accept multiple primary keys and delete records without retrieving them.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333399;\"><strong>Users-&gt;destroy(1,2,3);<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; The Eloquent ORM included with Laravel gives a wonderful, basic ActiveRecord usage for working along with your database. With eloquent, each table in the database corporate a comparing \u201cModel\u201d that does utilize to connect with that table.\u00a0 The model permits you to insert, update and delete the records from the table to recover or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6760,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[605],"tags":[609,606,608,607],"class_list":["post-6735","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-eloquent-orm-laravel","tag-laravel-eloquent","tag-laravel-eloquent-php","tag-laravel-eloquent-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Laravel Eloquent Tutorial With Examples - InnovationM<\/title>\n<meta name=\"description\" content=\"Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Laravel Eloquent Tutorial With Examples - InnovationM\" \/>\n<meta property=\"og:description\" content=\"Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-14T10:03:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-20T13:25:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/04\/Laravel-Eloquent.png\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Laravel Eloquent\",\"datePublished\":\"2021-04-14T10:03:22+00:00\",\"dateModified\":\"2023-01-20T13:25:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/\"},\"wordCount\":773,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Laravel-Eloquent.png\",\"keywords\":[\"Eloquent ORM - Laravel\",\"Laravel Eloquent\",\"Laravel Eloquent - PHP\",\"Laravel Eloquent Tutorial\"],\"articleSection\":[\"Laravel\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/\",\"name\":\"Laravel Eloquent Tutorial With Examples - InnovationM\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Laravel-Eloquent.png\",\"datePublished\":\"2021-04-14T10:03:22+00:00\",\"dateModified\":\"2023-01-20T13:25:05+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"description\":\"Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Laravel-Eloquent.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Laravel-Eloquent.png\",\"width\":960,\"height\":540,\"caption\":\"Laravel Eloquent\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/laravel-eloquent\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Laravel Eloquent\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Laravel Eloquent Tutorial With Examples - InnovationM","description":"Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/","og_locale":"en_US","og_type":"article","og_title":"Laravel Eloquent Tutorial With Examples - InnovationM","og_description":"Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database.","og_url":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/","og_site_name":"InnovationM - Blog","article_published_time":"2021-04-14T10:03:22+00:00","article_modified_time":"2023-01-20T13:25:05+00:00","og_image":[{"width":960,"height":540,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/04\/Laravel-Eloquent.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Laravel Eloquent","datePublished":"2021-04-14T10:03:22+00:00","dateModified":"2023-01-20T13:25:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/"},"wordCount":773,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/04\/Laravel-Eloquent.png","keywords":["Eloquent ORM - Laravel","Laravel Eloquent","Laravel Eloquent - PHP","Laravel Eloquent Tutorial"],"articleSection":["Laravel"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/","url":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/","name":"Laravel Eloquent Tutorial With Examples - InnovationM","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/04\/Laravel-Eloquent.png","datePublished":"2021-04-14T10:03:22+00:00","dateModified":"2023-01-20T13:25:05+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"description":"Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database.","breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/04\/Laravel-Eloquent.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/04\/Laravel-Eloquent.png","width":960,"height":540,"caption":"Laravel Eloquent"},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/laravel-eloquent\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Laravel Eloquent"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/6735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=6735"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/6735\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/6760"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=6735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=6735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=6735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}