Helpers

Helpers

table()

Looks for a data table by its slug. Returns an Eloquent query builder, on which you can chain to fetch what you need:

table('products')->where('published', 1)->orderBy('title')->get();

page()

Looks for a page by its slug, or returns the current page when the slug is omitted:

// Current page
page();

// Home page
page('home');

pages()

Returns an Eloquent query builder for the page table:

pages()->whereIn('slug', ['home', 'about', 'contact'])->get();

globals()

Looks for a global set by its slug. Returns an object to access the global values:

globals('general')->website_title;

languages()

Returns a collection of the languages of the project:

@foreach (languages() as $language)
    <a href="{{ $language->url() }}">{{ $language->name }}</a>
@endforeach

language()

Looks for a language by its slug, or returns the current language when the slug is omitted:

// Current language
language();

// Dutch language
language('nl');

breadcrumbs()

Returns a list of items, representing the breadcrumb path of the current page. Also works with dynamic pages:

@foreach (breadcrumbs() as $breadcrumb)
    <a href="{{ $breadcrumb->url() }}">{{ $breadcrumb->title() }}</a>
@endforeach

entry()

Returns the data entry corresponding with the current URL. This only works on dynamic pages and will return null on non-dynamic pages.

<h1>{{ entry()->title }}</h1>

mail()

Looks for a mail by its slug, to use in Livewire components. Several methods are available:

mail('subscription')
    ->to('name@example.com')
    ->cc('info@devisto.com')
    ->bcc('klaas@devisto.com')
    ->replyTo('klaas@devisto.com')
    ->parameter('name', $this->name)
    ->parameters(['name' => $this->name])
    ->send();

For more information on mails, take a look at the Mails section.

asset()

Looks for an asset by its path:

asset('path/to/test.jpg');

For more information on assets, take a look at the Assets section.

meta()

Helper method to register meta data. See Meta Data for more information.

unsplash()

Generates an Unsplash URL to get random free images for testing:

<img src="{{ unsplash()->search('nature')->size(400, 300) }}">
<img src="{{ unsplash()->user('User Name') }}">
<img src="{{ unsplash()->collection('Collection Name') }}">
<img src="{{ unsplash()->id('abc123') }}">

faker()

Returns a Faker instance to generate fake values for testing:

// Current language
faker()->firstName();

// Other Faker language
faker('nl_BE')->firstName();

The available methods are auto-suggested in the editor.

embed()

Generates the HTML to embed any service, just by giving it a URL:

{{ embed('https://twitter.com/devistoapp/status/1366841828696293380') }}
{{ embed('https://www.youtube.com/watch?v=A2Rxz8rR2Fk') }}

icon()

Generates the HTML code for an Fontawesome icon:

{{ icon('facebook') }}
{{ icon('facebook')->light() }}
{{ icon('facebook')->duotone() }}

The available icons are auto-suggested in the editor.

share()

Generates a URL to share a URL on several services:

// Current URL
share()->facebook();

// Other URL
share('https://...')->facebook();

// Available services
share()->facebook();
share()->twitter();
share()->linkedin();
share()->email()->subject('This is interesting');

str()

Returns a Laravel Stringable object, equivalant to Str::of() in Laravel:

// Chain methods
str('My Name')->snake()->upper(); // MY_NAME

// Omit the parameter to call 'Str' methods that don't expect a parameter
str()->random();

staging()

Returns true when you're in the staging environment, and false otherwise. See this section for more info about the different environments.

// Handy for testing
if (staging()) {
    logger()->info('This happened in staging');
}

// Equivalent to
if (app()->environment('staging')) {
    logger()->info('This happened in staging');
}

production()

Returns true when you're in the production environment, and false otherwise. See this section for more info about the different environments.

// Handy for testing
if (production()) {
    logger()->info('This happened in production');
}

// Equivalent to
if (app()->environment('production')) {
    logger()->info('This happened in production');
}

mollie()

Returns a Mollie client you can use to work with payments. Just provide your API key and you're good to go.

$payment = mollie('api_key')->payments->create([
    'amount' => [
        'currency' => 'EUR',
        'value' => '100.00',
    ],
    'description' => 'My order',
    'redirectUrl' => page('completed')->url(),
    'webhookUrl' => page('webhook')->url(),
]);

$url = $payment->getCheckoutUrl();

google()

Returns a Google client you can use to work with the Google API. You can find an example here.

$client = google('access_token');

guard()

Looks for a guard by its slug, to use in Livewire components. Several methods are available:

// Default guard
guard();

// Specific guard
guard('users');

user()

Returns the current logged in user.

@if (user())
    You are logged in as {{ user()->name }}.
@endif

Laravel Helpers

Of course, all default Laravel helpers are also available in Devisto, for example:

// Dates
now()->format('d/m/Y H:i:s');
today()->addDays(2)->format('d/m/Y');

// Debugging
dump('foo');
dd('foo');

// Getting data from the query string
request('foo', 'default');

// Make a collection
collect(['foo' => 'bar']);

Blade Directives

@styles

Renders all the CSS needed to make your project work:

  • All your own CSS you write in app.css
  • All styles you pushed to the stack with @push('styles')
  • Livewire styles to make Livewire components work

Typically, you'll want to include this directive in your master template before your closing </head> tag, like so:

<html>
    <head>
        ...
        @styles
    </head>
    ...
</html>

@scripts

Renders all the JavaScript needed to make your project work:

  • All your own JS you write in app.js
  • All scripts you pushed to the stack with @push('scripts')
  • Livewire scripts to make Livewire components work
  • Fontawesome scripts to make the icon() helper work
  • The instant.page script for faster page loads
  • The lazysizes script for faster image loading

Typically, you'll want to include this directive in your master template before your closing </body> tag, like so:

<html>
    ...
    <body>
        ...
        @scripts
    </body>
</html>

@meta

Renders all data that was registered with the meta() helper. See Meta Data for more information.

Typically, you'll want to include this directive in your master template after your opening <head> tag, like so:

<html>
    <head>
        @meta
        ...
    </head>
    ...
</html>

@staging

Can be used to check in Blade if you're in the staging environment:

@staging
    This is some debug info...
@endstaging

@production

Can be used to check in Blade if you're in the production environment:

@production
    {{-- My Google Analytics code --}}
@endproduction
Previous topic
← JS
Next topic
Meta Data →