{"id":1500,"date":"2017-01-13T10:05:16","date_gmt":"2017-01-13T10:05:16","guid":{"rendered":"http:\/\/myprojects.advchaweb.com\/?p=1500"},"modified":"2017-01-16T06:32:19","modified_gmt":"2017-01-16T06:32:19","slug":"laravel-tips-tricks","status":"publish","type":"post","link":"https:\/\/myprojects.advchaweb.com\/index.php\/2017\/01\/13\/laravel-tips-tricks\/","title":{"rendered":"Laravel Tips &#038; Tricks"},"content":{"rendered":"<p><span style=\"color: #ffff00;\">View (Template)<\/span><\/p>\n<ol>\n<li>How to show the data in the blade template (like var_dump function)?<br \/>\nSolution:<\/p>\n<pre class=\"lang:default decode:true\">@foreach($booking as $item)\r\n    {{ dd($item-&gt;toArray()) }}\r\n@endfor<\/pre>\n<p>use &#8216;dd&#8217; instead of var_dump. but var_dump also can be used to replace dd!<\/li>\n<li>How to concatenate strings?<br \/>\nSolution: Use &#8216;.&#8217; like in PHP<\/p>\n<pre class=\"lang:default decode:true \">$item-&gt;customer-&gt;first_name.' '.$item-&gt;customer-&gt;last_name<\/pre>\n<\/li>\n<li>How to check if variable is empty (null)?<br \/>\nSolution: Use &#8216;is_null()&#8217; like in PHP<\/p>\n<pre class=\"lang:default decode:true\">@if(is_null($item-&gt;customer)){{ $item-&gt;customer_id }}@else{{$item-&gt;customer-&gt;first_name.' '.$item-&gt;customer-&gt;last_name}}@endif<\/pre>\n<p>&nbsp;<\/li>\n<li>How to find out the array key\/index in foreach loop<br \/>\nSolution:<\/p>\n<pre class=\"lang:default decode:true\">@foreach($select_cities as $idx=&gt;$item)\r\n    &lt;div class=\"chk_city\"&gt;{!! Form::checkbox('city[]', $idx, null, ['class' =&gt; 'field']) !!} &lt;span&gt;{!! $item !!}&lt;\/span&gt;&lt;\/div&gt;\r\n@endforeach<\/pre>\n<p>Use &#8216;key=&gt;value&#8217; pair in foreach loop<\/li>\n<li>How to link to the css files in \/public\/css\/ directory?<br \/>\nSolution: Use &#8216;URL:asset()&#8217; like this<\/p>\n<pre class=\"lang:default decode:true \">&lt;link href=\"{{ URL::asset('css\/style.css') }}\" rel=\"stylesheet\"&gt;<\/pre>\n<p>&nbsp;<\/li>\n<\/ol>\n<p><span style=\"color: #ffff00;\">Model<\/span><\/p>\n<p><span style=\"color: #ffff00;\">Controller<\/span><\/p>\n<ol>\n<li>How to use Eloquent Query (select, join, group by, etc)<br \/>\nSolution: Use &#8216;DB::table&#8217;<br \/>\nTo use specific command like &#8216;GROUP_CONCAT&#8217;, use &#8216;DB::raw()&#8217;<br \/>\nDon&#8217;t put &#8216;get()&#8217; at the end of the query if the blade template use &#8216;render&#8217; but use &#8216;paginate()&#8217; instead<\/p>\n<pre class=\"lang:default decode:true \">$cleaner = DB::table('cleaners')\r\n                -&gt;join('cleaner_cities','cleaners.id','=','cleaner_cities.cleaner_id')\r\n                -&gt;join('cities','cleaner_cities.city_id','=','cities.id')\r\n                -&gt;select('cleaners.id','cleaners.first_name','cleaners.last_name','cleaners.quality_score',DB::raw('(GROUP_CONCAT(cities.city_name)) AS city'))\r\n                -&gt;groupBy('cleaners.id','cleaners.first_name','cleaners.last_name','cleaners.quality_score')\r\n                -&gt;paginate(25);\r\n\r\nreturn view('admin.cleaner.index', compact('cleaner'));<\/pre>\n<p>&nbsp;<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>View (Template) How to show the data in the blade template (like var_dump function)? Solution: @foreach($booking as $item) {{ dd($item-&gt;toArray()) }} @endfor use &#8216;dd&#8217; instead of var_dump. but var_dump also can be used to replace dd! How to concatenate strings? Solution: Use &#8216;.&#8217; like in PHP $item-&gt;customer-&gt;first_name.&#8217; &#8216;.$item-&gt;customer-&gt;last_name How to check if variable is empty &hellip; <a href=\"https:\/\/myprojects.advchaweb.com\/index.php\/2017\/01\/13\/laravel-tips-tricks\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Laravel Tips &#038; Tricks&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,13],"tags":[],"class_list":["post-1500","post","type-post","status-publish","format-standard","hentry","category-laravel","category-tutorial"],"_links":{"self":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=1500"}],"version-history":[{"count":7,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1500\/revisions"}],"predecessor-version":[{"id":1525,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1500\/revisions\/1525"}],"wp:attachment":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=1500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=1500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=1500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}