{"id":6379,"date":"2014-04-17T01:13:41","date_gmt":"2014-04-17T01:13:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/17\/passing-objects-to-custom-control-structures-in-laravel-blade-collection-of-common-programming-errors-2\/"},"modified":"2022-08-30T15:45:33","modified_gmt":"2022-08-30T15:45:33","slug":"passing-objects-to-custom-control-structures-in-laravel-blade-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/17\/passing-objects-to-custom-control-structures-in-laravel-blade-collection-of-common-programming-errors-2\/","title":{"rendered":"Passing objects to Custom Control Structures in Laravel Blade-Collection of common programming errors"},"content":{"rendered":"<p>I can&#8217;t call member functions on objects that I pass to custom control structures in Laravel 4.1.23.<\/p>\n<p>My custom control structure:<\/p>\n<pre><code>Blade::extend(function($view, $compiler){\n    $pattern = $compiler-&gt;createMatcher('paginatePretty');\n    $code = \n        '$1';\n    return preg_replace($pattern, $code, $view);\n});\n<\/code><\/pre>\n<p>My blade view code that instantiates paginatePretty:<\/p>\n<pre><code>\/\/ $articles = Articles::orderBy('created_at', 'desc')-&gt;paginate($per_page);\n@paginatePretty($articles)\n<\/code><\/pre>\n<p>At compile time, I get this error:<\/p>\n<pre><code>syntax error, unexpected '-&gt;' (T_OBJECT_OPERATOR), expecting ',' or ';'\n<\/code><\/pre>\n<p>And the custom control structure was compiled like this:<\/p>\n<pre><code>echo ($articles)-&gt;getCurrentPage();\n<\/code><\/pre>\n<p>How can I pass an object to the custom control structure?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I can&#8217;t call member functions on objects that I pass to custom control structures in Laravel 4.1.23. My custom control structure: Blade::extend(function($view, $compiler){ $pattern = $compiler-&gt;createMatcher(&#8216;paginatePretty&#8217;); $code = &#8216;$1&#8217;; return preg_replace($pattern, $code, $view); }); My blade view code that instantiates paginatePretty: \/\/ $articles = Articles::orderBy(&#8216;created_at&#8217;, &#8216;desc&#8217;)-&gt;paginate($per_page); @paginatePretty($articles) At compile time, I get this error: syntax [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1],"tags":[],"class_list":["post-6379","post","type-post","status-publish","format-standard","hentry","category-laravel","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6379"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6379\/revisions"}],"predecessor-version":[{"id":8830,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6379\/revisions\/8830"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}