Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

nztim/helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel 5 Helpers

  • Register the service provider: NZTim\Helpers\HelpersServiceProvider

Helper functions

  • autolink(string $content) - autolink a string
  • flash($message, $type = 'danger') - send flash messages to the view
  • markdown(string $content) - renders Markdown GFM style including line breaks
  • sanitize(mixed $data) - runs htmlspecialchars() and trim() on a string or an array of strings
  • cached_asset($path) - returns asset path with hashed integer value, e.g. main.css -> main.847389233.css
    • Note: .htaccess rule is required, see below

Blade directives

  • @autolink($string) - sanitizes the string, autolinks and runs nl2br
  • @formerror - echoes the error message with a Bootstrap-compatible red background
  • @markdown - Renders markdown, HTML-escapes the content (using Parsedown)
  • @nl2br($string) - sanitizes the string and then runs nl2br
  • @pagination($paginator) - calls render()

Validator extensions

  • commonpwd - ensures a password is not on a list of 10,000 common passwords
  • fileext:jpg,jpeg,png,gif - validates file extension
  • after_or_equal:2019-11-01 - date is after or equal date provided, uses strtotime for comparison

.htaccess for cached_asset()

Add this before the Laravel rewrite rule

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]
</IfModule>

Envcheck command

Add php artisan envcheck to your deploy process to enable a comparison check between .env and .env.example

Local configuration (.env replacement)

To use this functionality add this method override to your HTTP and Console Kernel classes:

protected function bootstrappers()
{
    return array_merge([\NZTim\Helpers\Local\Local::class], $this->bootstrappers);
}

Replace your .env[.example] file with local[.dist].php, which uses normal config file format.
Add local.php to your .gitignore.
Now you can use local() in your config files in the same way that you use env() but without the downsides.

Updating

  • 3.0: Removed markdown handling, replace by installing nztim/markdown

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages