{"id":1342,"date":"2023-10-31T14:17:21","date_gmt":"2023-10-31T14:17:21","guid":{"rendered":"https:\/\/www.devopsfreelancer.com\/blog\/?p=1342"},"modified":"2023-10-31T14:17:22","modified_gmt":"2023-10-31T14:17:22","slug":"what-are-the-example-of-encapsulation-in-laravel","status":"publish","type":"post","link":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/","title":{"rendered":"What are the example of encapsulation in Laravel ?"},"content":{"rendered":"\n<p>In this tutorial i&#8217;m going to learn what are the example of encapsulation in laravel so follow this tutorial i have mentioned in very easy way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is encapsulation ?<\/strong><\/h2>\n\n\n\n<p>Encapsulation is a core concept in object-oriented programming (OOP). It refers to the bundling of data and the methods that operate on that data into a single unit. This allows developers to control how the data is accessed and manipulated, which can improve the security, reliability, and maintainability of the code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example :-<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\nnamespace App\\Models;\r\n\r\nclass User\r\n{\r\n    private $name;\r\n    private $email;\r\n    private $password;\r\n\r\n    public function __construct($name, $email, $password)\r\n    {\r\n        $this->name = $name;\r\n        $this->email = $email;\r\n        $this->password = $password;\r\n    }\r\n\r\n    public function getName()\r\n    {\r\n        return $this->name;\r\n    }\r\n\r\n    public function setName($name)\r\n    {\r\n        $this->name = $name;\r\n    }\r\n\r\n    public function getEmail()\r\n    {\r\n        return $this->email;\r\n    }\r\n\r\n    public function setEmail($email)\r\n    {\r\n        $this->email = $email;\r\n    }\r\n\r\n    public function setPassword($password)\r\n    {\r\n        $this->password = $password;\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<p>In this example, the <code class=\"\">User<\/code> class encapsulates the user&#8217;s name and email address. The name and email address are private members, which means that they can only be accessed through the public getter and setter methods. This prevents the user&#8217;s name and email address from being accidentally or maliciously modified.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Encapsulation has a number of benefits, including:<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Data protection:<\/strong>&nbsp;Encapsulation helps to protect the data from being accidentally or maliciously modified.<\/li>\n\n\n\n<li><strong>Code reusability:<\/strong>&nbsp;Encapsulation makes code more reusable by hiding the internal implementation details of the class.<\/li>\n\n\n\n<li><strong>Testability:<\/strong>&nbsp;Encapsulation makes code more testable by isolating the data and the code that operates on that data.<\/li>\n\n\n\n<li><strong>Maintainability:<\/strong>&nbsp;Encapsulation makes code more maintainable by making it easier to change the internal implementation of the class without affecting the code that uses it.<\/li>\n<\/ol>\n\n\n\n<p>Encapsulation is a powerful concept that can be used to improve the quality of software.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial i&#8217;m going to learn what are the example of encapsulation in laravel so follow this tutorial i have mentioned in very easy way. What&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[525,3,526,11],"class_list":["post-1342","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-encapsulation","tag-laravel","tag-oops-in-laravel","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What are the example of encapsulation in Laravel ? - DevOps Freelancer<\/title>\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.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What are the example of encapsulation in Laravel ? - DevOps Freelancer\" \/>\n<meta property=\"og:description\" content=\"In this tutorial i&#8217;m going to learn what are the example of encapsulation in laravel so follow this tutorial i have mentioned in very easy way. What...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps Freelancer\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/amitsthakurs\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-31T14:17:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-31T14:17:22+00:00\" \/>\n<meta name=\"author\" content=\"Amit Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/amits_thakurs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amit Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/\"},\"author\":{\"name\":\"Amit Kumar\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"headline\":\"What are the example of encapsulation in Laravel ?\",\"datePublished\":\"2023-10-31T14:17:21+00:00\",\"dateModified\":\"2023-10-31T14:17:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/\"},\"wordCount\":241,\"commentCount\":0,\"keywords\":[\"encapsulation\",\"laravel\",\"oops-in-laravel\",\"php\"],\"articleSection\":[\"Laravel\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/\",\"name\":\"What are the example of encapsulation in Laravel ? - DevOps Freelancer\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#website\"},\"datePublished\":\"2023-10-31T14:17:21+00:00\",\"dateModified\":\"2023-10-31T14:17:22+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/what-are-the-example-of-encapsulation-in-laravel\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What are the example of encapsulation in Laravel ?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/\",\"name\":\"DevOps Freelancer\",\"description\":\"We provide DevOps | SRE | DevSecOps | MLOps Freelancing\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\",\"name\":\"Amit Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"caption\":\"Amit Kumar\"},\"description\":\"Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer\\\/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/amitsthakurs\\\/\",\"https:\\\/\\\/www.instagram.com\\\/amits_thakurs\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/amits-thakurs\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/amits_thakurs\"],\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/author\\\/amit\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What are the example of encapsulation in Laravel ? - DevOps Freelancer","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.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/","og_locale":"en_US","og_type":"article","og_title":"What are the example of encapsulation in Laravel ? - DevOps Freelancer","og_description":"In this tutorial i&#8217;m going to learn what are the example of encapsulation in laravel so follow this tutorial i have mentioned in very easy way. What...","og_url":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/","og_site_name":"DevOps Freelancer","article_author":"https:\/\/www.facebook.com\/amitsthakurs\/","article_published_time":"2023-10-31T14:17:21+00:00","article_modified_time":"2023-10-31T14:17:22+00:00","author":"Amit Kumar","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/amits_thakurs","twitter_misc":{"Written by":"Amit Kumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/#article","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/"},"author":{"name":"Amit Kumar","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"headline":"What are the example of encapsulation in Laravel ?","datePublished":"2023-10-31T14:17:21+00:00","dateModified":"2023-10-31T14:17:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/"},"wordCount":241,"commentCount":0,"keywords":["encapsulation","laravel","oops-in-laravel","php"],"articleSection":["Laravel"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/","url":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/","name":"What are the example of encapsulation in Laravel ? - DevOps Freelancer","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#website"},"datePublished":"2023-10-31T14:17:21+00:00","dateModified":"2023-10-31T14:17:22+00:00","author":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"breadcrumb":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopsfreelancer.com\/blog\/what-are-the-example-of-encapsulation-in-laravel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopsfreelancer.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What are the example of encapsulation in Laravel ?"}]},{"@type":"WebSite","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#website","url":"https:\/\/www.devopsfreelancer.com\/blog\/","name":"DevOps Freelancer","description":"We provide DevOps | SRE | DevSecOps | MLOps Freelancing","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopsfreelancer.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b","name":"Amit Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","caption":"Amit Kumar"},"description":"Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer\/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.","sameAs":["https:\/\/www.facebook.com\/amitsthakurs\/","https:\/\/www.instagram.com\/amits_thakurs\/","https:\/\/www.linkedin.com\/in\/amits-thakurs\/","https:\/\/x.com\/https:\/\/twitter.com\/amits_thakurs"],"url":"https:\/\/www.devopsfreelancer.com\/blog\/author\/amit\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/1342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/comments?post=1342"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/1342\/revisions"}],"predecessor-version":[{"id":1343,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/1342\/revisions\/1343"}],"wp:attachment":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/media?parent=1342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/categories?post=1342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/tags?post=1342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}