{"id":501,"date":"2023-06-26T06:46:02","date_gmt":"2023-06-26T06:46:02","guid":{"rendered":"https:\/\/www.devopsfreelancer.com\/blog\/?p=501"},"modified":"2023-06-26T06:46:04","modified_gmt":"2023-06-26T06:46:04","slug":"define-of-laravel-contracts-what-is-contracts","status":"publish","type":"post","link":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/","title":{"rendered":"Define of Laravel &#8211; Contracts | What is Contracts ?"},"content":{"rendered":"\n<p>In this tutorial we&#8217;re going to learn what is Contracts and how to using it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Contracts ?<\/h2>\n\n\n\n<p>Laravel contracts are a set of interfaces with various functionalities and core services provided by the framework.<\/p>\n\n\n\n<p>For example,&nbsp;<strong>Illuminate\\Contracts\\Queue\\Queue<\/strong>&nbsp;contract uses a method which is needed for queuing jobs and&nbsp;<strong>Illuminate\\Contracts\\Mail\\Mailer<\/strong>&nbsp;uses the method for sending emails.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Important Points<\/h2>\n\n\n\n<p>While working with Laravel contracts, please note the following important points \u2212<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is mandatory to define facades in the constructor of a class.<\/li>\n\n\n\n<li>Contracts are explicitly defined in the classes and you need not define the contracts in constructors.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<p>Consider the contract used for Authorization in Laravel which is mentioned below \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\nnamespace Illuminate\\Contracts\\Auth\\Access;\r\n\r\ninterface Authorizable{\r\n   \/**\r\n      * Determine if the entity has a given ability.\r\n      *\r\n      * @param string $ability\r\n      * @param array|mixed $arguments\r\n      * @return bool\r\n   *\/\r\n   public function can($ability, $arguments = &#91;]);\r\n}<\/code><\/pre>\n\n\n\n<p>The contract uses a function can which includes a\u00a0parameter\u00a0named\u00a0ability\u00a0and\u00a0arguments\u00a0which uses the user identification in the form of an\u00a0array.<\/p>\n\n\n\n<p>You will have to define a contract as shown in the syntax below \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>interface &lt;contract-name>\n<\/code><\/pre>\n\n\n\n<p>Contracts are used like facades for creating robust, well-tested Laravel applications. There are various\u00a0practical differences\u00a0with usage of contracts and facades.<\/p>\n\n\n\n<p>The following code shows using a contract for caching a repository \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\nnamespace App\\Orders;\r\nuse Illuminate\\Contracts\\Cache\\Repository as Cache;\r\n\r\nclass Repository{\r\n   \/**\r\n      * The cache instance.\r\n   *\/\r\n   \r\n   protected $cache;\r\n   \r\n   \/**\r\n      * Create a new repository instance.\r\n      *\r\n      * @param Cache $cache\r\n      * @return void\r\n   *\/\r\n   \r\n   public function __construct(Cache $cache) {\r\n      $this->cache = $cache;\r\n   }\r\n}<\/code><\/pre>\n\n\n\n<p>Contract contains no implementation and new dependencies; it is easy to write an alternative implementation of a specified contract, thus a user can replace cache implementation without modifying any code base.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we&#8217;re going to learn what is Contracts and how to using it. What is Contracts ? Laravel contracts are a set of interfaces with&#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":[180,181,3],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-contracts-function","tag-how-to-use-contracts-function","tag-laravel"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Define of Laravel - Contracts | What is Contracts ? - 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\/define-of-laravel-contracts-what-is-contracts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Define of Laravel - Contracts | What is Contracts ? - DevOps Freelancer\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we&#8217;re going to learn what is Contracts and how to using it. What is Contracts ? Laravel contracts are a set of interfaces with...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/\" \/>\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-06-26T06:46:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-26T06:46:04+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/\"},\"author\":{\"name\":\"Amit Kumar\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"headline\":\"Define of Laravel &#8211; Contracts | What is Contracts ?\",\"datePublished\":\"2023-06-26T06:46:02+00:00\",\"dateModified\":\"2023-06-26T06:46:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/\"},\"wordCount\":231,\"commentCount\":0,\"keywords\":[\"contracts-function\",\"how-to-use-contracts-function\",\"laravel\"],\"articleSection\":[\"Laravel\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/\",\"name\":\"Define of Laravel - Contracts | What is Contracts ? - DevOps Freelancer\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#website\"},\"datePublished\":\"2023-06-26T06:46:02+00:00\",\"dateModified\":\"2023-06-26T06:46:04+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/define-of-laravel-contracts-what-is-contracts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Define of Laravel &#8211; Contracts | What is Contracts ?\"}]},{\"@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":"Define of Laravel - Contracts | What is Contracts ? - 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\/define-of-laravel-contracts-what-is-contracts\/","og_locale":"en_US","og_type":"article","og_title":"Define of Laravel - Contracts | What is Contracts ? - DevOps Freelancer","og_description":"In this tutorial we&#8217;re going to learn what is Contracts and how to using it. What is Contracts ? Laravel contracts are a set of interfaces with...","og_url":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/","og_site_name":"DevOps Freelancer","article_author":"https:\/\/www.facebook.com\/amitsthakurs\/","article_published_time":"2023-06-26T06:46:02+00:00","article_modified_time":"2023-06-26T06:46:04+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":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/#article","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/"},"author":{"name":"Amit Kumar","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"headline":"Define of Laravel &#8211; Contracts | What is Contracts ?","datePublished":"2023-06-26T06:46:02+00:00","dateModified":"2023-06-26T06:46:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/"},"wordCount":231,"commentCount":0,"keywords":["contracts-function","how-to-use-contracts-function","laravel"],"articleSection":["Laravel"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/","url":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/","name":"Define of Laravel - Contracts | What is Contracts ? - DevOps Freelancer","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#website"},"datePublished":"2023-06-26T06:46:02+00:00","dateModified":"2023-06-26T06:46:04+00:00","author":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"breadcrumb":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopsfreelancer.com\/blog\/define-of-laravel-contracts-what-is-contracts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopsfreelancer.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Define of Laravel &#8211; Contracts | What is Contracts ?"}]},{"@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\/501","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=501"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":502,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/501\/revisions\/502"}],"wp:attachment":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/media?parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/categories?post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/tags?post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}