Laravel Tips & Tricks

View (Template)

  1. How to show the data in the blade template (like var_dump function)?
    Solution:

    use ‘dd’ instead of var_dump. but var_dump also can be used to replace dd!
  2. How to concatenate strings?
    Solution: Use ‘.’ like in PHP
  3. How to check if variable is empty (null)?
    Solution: Use ‘is_null()’ like in PHP

     
  4. How to find out the array key/index in foreach loop
    Solution:

    Use ‘key=>value’ pair in foreach loop
  5. How to link to the css files in /public/css/ directory?
    Solution: Use ‘URL:asset()’ like this

     

Model

Controller

  1. How to use Eloquent Query (select, join, group by, etc)
    Solution: Use ‘DB::table’
    To use specific command like ‘GROUP_CONCAT’, use ‘DB::raw()’
    Don’t put ‘get()’ at the end of the query if the blade template use ‘render’ but use ‘paginate()’ instead

     

Leave a Reply

Your email address will not be published. Required fields are marked *