{"id":11341,"date":"2020-02-28T13:08:30","date_gmt":"2020-02-28T13:08:30","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=11341"},"modified":"2021-11-12T06:46:04","modified_gmt":"2021-11-12T06:46:04","slug":"how-to-check-variable-is-declared-or-not-in-laravel-to-avoid-an-error","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-check-variable-is-declared-or-not-in-laravel-to-avoid-an-error\/","title":{"rendered":"How to check variable is declared or not in Laravel to avoid an Error."},"content":{"rendered":"\n<p>Suppose we have not declared a variable in the controller and calling it in views, then it shows <strong><em>undefined variable Error<\/em><\/strong>. See the below image.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/undefined-variable-error-1024x517.png\" alt=\"\" class=\"wp-image-11346\" width=\"580\" height=\"292\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/undefined-variable-error-1024x517.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/undefined-variable-error-300x151.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/undefined-variable-error-768x387.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/undefined-variable-error.png 1362w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/figure><\/div>\n\n\n\n<p>Suppose, we are calling <strong>$string<\/strong> variable and we have not declared the variable in the controller so it gives an error like above shown.<br>To avoid this error we use <strong><em>@isset<\/em><\/strong> function. See the below image for code.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"335\" height=\"165\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/isset-function.png\" alt=\"\" class=\"wp-image-11349\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/isset-function.png 335w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/isset-function-300x148.png 300w\" sizes=\"auto, (max-width: 335px) 100vw, 335px\" \/><\/figure><\/div>\n\n\n\n<p>as we have not declared the string so it returns <strong>Variable is not found<\/strong>. See the below image.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"373\" height=\"196\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/isset-output.png\" alt=\"\" class=\"wp-image-11355\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/isset-output.png 373w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/02\/isset-output-300x158.png 300w\" sizes=\"auto, (max-width: 373px) 100vw, 373px\" \/><\/figure><\/div>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_96086\"><iframe loading=\"lazy\"  id=\"_ytid_19987\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_96086\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Suppose we have not declared a variable in the controller and calling it in views, then it shows undefined variable Error. See the below image. Suppose, we are calling $string&#8230; <\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5201],"tags":[],"class_list":["post-11341","post","type-post","status-publish","format-standard","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=11341"}],"version-history":[{"count":10,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11341\/revisions"}],"predecessor-version":[{"id":24903,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11341\/revisions\/24903"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=11341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=11341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=11341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}