Then you probably want a configuration file, editable as you like, with a few default config and examples. To generate the
config/larastrap.php file, run
Be aware you still have to install Bootstrap assets (both CSS and JS) in your page, with you preferred method (
npm i bootstrap, deeplinking the CDN or whatever). It is suggested to use the laravel/ui package to start up your new application.
Larastrap is a collection of Blade Components, as defined by the Laravel's documentation.
Those can be used in any Blade template using the syntax
or, for Containers
<x-larastrap::componentname> contents </x-larastrap::componentname>
Each element accepts a variety of parameters, that can be passed inline using HTML attributes (whose name have to be prefixed with a
: character when handling a PHP expression).
<x-larastrap::componentname id="a_static_string" :name="$a_php_variable" />
Parameters can also be massively passed through the params parameter, in a single array.
<x-larastrap::componentname :params="['id' => a_static_string, 'name' => $a_php_variable]" />
Remember that, as per native Blade Components' behavior, is also possible to dynamically invoke a component by his own name using the
<x-dynamic-component :component="sprintf('larastrap::%s', $a_component_type)" :params="['id' => 'a_static_string', 'name' => $a_php_variable]" />
Check the documentation of each different element to discover more about his usage, the accepted parameters, the implicit features and behaviors and more!
The whole configuration of Larastrap is centered on the many possible parameters assignable to each element, each having his own meaning.
Parameters' values are evaluated accordingly to a given priority sequence:
This hierarchy permits a fine-grained configuration: a global one, intended to keep the whole behaviors coherent within the application, and the ability to specify each parameter only when required.
Given the following sample file:
<?php return [ 'commons' => [ 'color' => 'danger', ], 'elements' => [ 'button' => [ 'color' => 'success', ] ], 'customs' => [ 'mybutton' => [ 'extends' => 'button', 'params' => [ 'color' => 'warning', ] ] ], ];
All elements will have a default color
, apart for x-larastrap::button
that will have color
. When instead using the custom element x-larastrap::mybutton
, even if it extends the base x-larastrap::button
type, it will have color
Most of the internal state of Larastrap is kept into the
service container, a singleton instantiated by Larastrap's Service Provider. It exposes a few utility function, including one to override the configuration usually get from the
<?php $stack = app()->make('LarastrapStack'); /* From here, all forms have use the horizontal formview (despite what is written in the configuration file). The configuration of all other component types is left untouched. */ $stack->overrideNodesConfig([ 'form' => [ 'formview' => 'horizontal' ] ]); /* Restores the configuration from the file */ $stack->overrideNodesConfig(null);