Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
These are standard attributes for number input field, default value for step is any if not defined.
Support for Laravel 5.4 was dropped in Voyager 1.2 and therefore the minimum PHP version is now 7.1. Please update your versions accordingly!
To update to the latest version inside of your composer.json file make sure to update the version of Voyager inside the require declaration inside of your composer.json to:
tcg/voyager": "1.2.*
And then run composer update
The voyager.php
configuration file had a few changes.
is now
Also, the option
was added. This allows you to exclude Voyagers migration-files from loading when running php artisan migrate
.
There is a new section titled Model specific settings that contains new settings for Compass, cache and media-manager.
Compass is now switched off automatically when the environment is not local
.
This can be overriden by the following new config-key:
New cache setting:
The media-manager got some new configuration-options:
The top dropdown-items can now be translated by providing a language-key:
If you were using casts in your user-model previously, please remove the array-cast of settings
.
can
, canOrAbort
, canOrFail
in the Voyager facade were all removed in favor of Policies and Gates.
Please refer to the Laravel documentation.
Voyager changed its way on how to load assets.
Assets don't get published anymore, instead they are loaded directly from the package.
Because of that, you can safely remove everything from your public/vendor/tcg/voyager
folder.
Also you can remove the assets_path
config-key from config/voyager.php
.
Be sure to ask us on our slack channel if you are experiencing any issues and we will try and assist. Thanks.
The User BREAD now has its own controller. Please update your User BREAD to use TCG\Voyager\Http\Controllers\VoyagerUserController
as the controller:
With the installation of Voyager you will find a new configuration file located at config/voyager.php
.
In this file you can find various options to change the configuration of your Voyager installation.
If you cache your configuration files please make sure to run php artisan config:clear
after you changed something.
Below we will take a deep dive into the configuration file and give a detailed description of each configuration set.
add_default_role_on_register: Specify whether you would like to add the default role to any new user that is created. default_role: You can also specify what the default_role is of the user. admin_permission: The permission needed to view the admin dashboard. namespace: The namespace of your apps User Class. redirect: Redirect path after the user logged in.
You can specify the default controller
namespace of Voyager. If you ever wish to override any of the core functionality of Voyager you can do so by duplicating the Voyager controllers and specifying the location of your custom controllers.
Overwrite a single controller
If you only want to overwrite a single controller, you might consider adding the following piece of code to your AppServiceProvider
class in the register
method.
$this->app->bind(VoyagerBreadController::class, MyBreadController::class);
You can specify the namespace or location of your models. This is used when creating the Models from the database section of Voyager. If not defined the default application namespace will be used.
You may wish to specify a different asset path. If your site lives in a subfolder you may need to include that directory to the beginning of the path. This may also be used in case you wish to duplicate the published assets and customize your own.
When upgrading to new version of voyager the assets located in the /vendor/tcg/voyager/assets
directory may need to be overwritten, so if you wish to customize any styles you will want to duplicate that directory and specify the new location of your asset_path.
By default Voyager is going to use the public
local storage. You can additionally use any driver inside of your config/filesystems.php
. This means you can use S3, Google Cloud Storage, or any other file storage system you would like.
You may wish to hide some database tables in the Voyager database section. In the database config you can choose which tables would like to hide.
autoload_migrations
allows you to exclude Voyagers migration-files from loading when running php artisan migrate
.
You can specify whether or not you want to enable mutliple languages. You can then specify your default language and all the support languages (locales)
Read more about multilanguage here.
In the dashboard config you can add navbar_items, make the data_tables responsive, and manage your dashboard widgets.
navbar_items Include a new route in the main user navbar dropdown by including a 'route', 'icon_class', and 'target_blank'.
data_tables If you set 'responsive' to true the datatables will be responsive.
widgets Here you can manage the widgets that live on your dashboard. You can take a look at an example widget class by viewing the current widgets inside of tcg/voyager/src/Widgets
.
The default primary color for the Voyager admin dashboard is a light blue color. You can change that primary color by changing the value of this config.
In the Voyager admin there are developer tips or notifications that will show you how to reference certain values from Voyager. You can choose to hide these notifications by setting this configuration value to false.
You can add your own custom stylesheets that will be included in the Voyager admin dashboard. This means you could technically create a whole new theme for Voyager by adding your own custom stylesheet.
Read more here.
The path will be passed to Laravels asset function.
The same goes for this configuration. You can add your own javascript that will be executed in the Voyager admin dashboard. Add as many javascript files as needed.
Read more here.
There is a new data type called coordinates that allow you to add a google map as a datatype. The user can then drag and drop a pin in the Google Maps to save a longitude and latitude value in the database.
In this config you can set the default Google Maps Keys and center location. This can also be added to your .env file.
To allow/disallow mimetypes to be uploaded through the media-manager you can define an array allowed_mimetypes
:
The user can only upload files with the given mimetypes. If you want to allow all types to be uploaded you can use the following:
Before installing Voyager it is very important to take a quick moment to learn what it is & what it isn't.
An admin interface for your Laravel app
An easy way to add/edit/delete data for your app
A menu builder (build menus in Voyager for your app)
A media manager for your files
CRUD/BREAD generator (learn more about BREAD here)
Voyager is simply an admin for your Laravel app. Whatever you want your app to do on the front-end is completely up to you. You are in control of your application and you can use Voyager to make your life easier by adding data, editing users, creating menus, and many other administrative tasks.
A content management system (CMS)
A blogging platform
Wordpress (Bleh! 😜)
Voyager is not a CMS or a blogging platform. But it can be used to create a CMS or a blogging platform, but out of the box it is neither of those. As stated in the previous section you have full control on what your application will do and how it will function.
With Laravel & Voyager you can create any kind of application your heart desires. Laravel & Voyager are simply tools to make it easier to build.
Voyager is super easy to install. After creating your new Laravel application you can include the Voyager package with the following command:
Next make sure to create a new database and add your database credentials to your .env file, you will also want to add your application URL in the APP_URL
variable:
Using Laravel 5.4? If you are installing with Laravel 5.4 you will need to add the Service Provider manually. Otherwise, if you are on 5.5 this happens automatically thanks to package auto-discovery.
Finally, we can install Voyager. You can choose to install Voyager with dummy data or without the dummy data. The dummy data will include 1 admin account (if no users already exist), 1 demo page, 4 demo posts, 2 categories and 7 settings.
To install Voyager without dummy data simply run
If you prefer installing it with the dummy data run the following command:
Specified key was too long error If you see this error message you have an outdated version of MySQL, use the following solution: https://laravel-news.com/laravel-5-4-key-too-long-error
And we're all good to go!
Start up a local development server with php artisan serve
And, visit the URL http://localhost:8000/admin in your browser.
If you installed with the dummy data, a user has been created for you with the following login credentials:
email:
admin@admin.com
password:password
Quick note A dummy user is only created if there are no current users in your database.
If you did not go with the dummy user, you may wish to assign admin priveleges to an existing user. This can easily be done by running this command:
If you wish to create a new admin user you can pass the --create
flag, like so:
And you will be prompted for the users name and password.
This is only required if you are using Laravel 5.4! If you are on Laravel 5.5+ you can skip this step.
To add the Voyager Service Provider open up your application config/app.php
file and add TCG\Voyager\VoyagerServiceProvider::class,
in the providers
array like so:
This section is meant for users who are installing Voyager on an already existing Laravel installation or for users who want to perform a manual install. If this is not the case, you should go back to the installation documentation or skip this section.
The first thing you should do is publish the assets that come with Voyager. You can do that by running the following commands:
Next, call php artisan migrate
to migrate all Voyager table.
If you want to change migrations, for example to use a different table for users, don't migrate. Instead copy Voyagers migrations to database/migrations
, make your changes, turn off the config option database.autoload_migrations
and then migrate.
Now, open your User-Model (usually app/User.php
) and make the class extend \TCG\Voyager\Models\User
instead of Authenticatable
.
The next step is to add Voyagers routes to your routes/web.php
file:
Now run
php artisan db:seed --class=VoyagerDatabaseSeeder
to seed some necessary data to your database,
php artisan hook:setup
to install the hooks system, and
php artisan storage:link
to create the storage symlink to your public folder.
After that, run composer dump-autoload
to finish your installation!
Welcome to the Voyager documentation for version 1.2. This documentation will teach you how to install, configure, and use Voyager so that way you can create some kick ass stuff!
Hm Hm (cough)… I mean… Arrgg! Ye young scallywag! What say we learn how to steer this ship!
Before installing Voyager you may want to take a quick moment to learn what is is and what it isn't, we'll do that in the next section.
Using the BREAD builder you can easily create Relationships between tables. At the bottom of the page you will see a new button that says 'Create Relationship'
Notice If you have not yet created the BREAD for the table yet, it will need to be created first and then you can come back after creating the BREAD to add the relationship. Otherwise you'll end up with a notification which looks like the following.
So, after the BREAD has already been created you will then be able to create a new relationship. After you click on the 'Create a Relationship' button. You will see a new Modal window that looks like the following:
You will first specify which type of relationship this is going to be, then you will select the table you are referencing and which Namespace that belongs to that table. You will then select which row combines those tables.
You can also specify which columns you would like to see in the dropdown or the multi-select.
Now, you can easily create belongsTo
, belongsToMany
, hasOne
, and hasMany
relationships directly in Voyager.
When adding or editing the current BREAD for a database table you will first see the BREAD info which allows you to set the Display Names, slug, icon, Model
and Controller Namespace, Policy Name. You can also choose if you would like to Generate permissions for that BREAD type.
When you scroll down you will see each of the rows that are associated with that table where you can select where in your views you want to see each of those fields:
BROWSE (field will show up when you browse the current data)
READ (field will show when you click to view the current data)
EDIT (field will be visible and allow you to edit the data)
ADD (field will be visible when you choose to create a new data type)
DELETE (doesn't pertain to delete so this can be checked or unchecked)
You may also choose to specify what form type you want to use for each field. This can be a TextBox, TextArea, Checkbox, Image, and many other types of form elements.
Each field also has additional details or options that can be included. These types are checkbox, dropdown, radio button, and image.
Inside of the Optional Details section for each row in your BREAD you can also specify validation rules with some simple JSON. Here is an example of how to add a validation rule for required and max length of 12
Additionally, you may wish to add some custom error messages which can be accomplished like so:
You can also define multiple rules the following way:
You can define separate validation rules for edit and add:
You can find a list of all available validation rules in the Laravel docs.
Tagging gives you the possibility to add new items to a Belongs-To-Many relationship directly when editing or adding a BREAD.
To activate this function, you simply have to enable Tagging
in the relationship details
After that you can enter a free-text into the select and hit enter to save a new relationship.
Be aware:
This only stores the display-column
so you have to make sure that all other fields are either nullable or have a default value.
You can define the default order for browsing BREADs and order your BREAD items with drag-and-drop. For this you need to change the settings for your BREAD first:
Order column is the field in your table where the order is stored as an integer. Order display column is the field which is shown in the drag-drop list. Order direction the direction in which the field is ordered.
After this you can go to your BREAD-browse page and you will see a button Order. Clicking this button will bring you to the page where you can re-arrange your items:
If you want to filter the browse results for a BREAD you can do so by creating a Scope in your model. For example if you want to only show posts that were created by the current user, define a Scope like the following:
Next, go to the BREAD-settings for posts
and look for the Scope
input and select currentUser
:
After hitting Submit
you will only see your own posts.
In Voyager a Checkbox is converted into a toggle switch, and as you can see above the on
key will contain the value when the toggle switch is on, and the off
will contain the value that is set when the switch is off. If checked
is set to true the checkbox will be toggle on; otherwise by default it will be off.
You can create as many checkboxes as you want.
The Radio button is exactly the same as the dropdown. You can specify a default
if one has not been set and in the options
object you will specify the value of the option on the left and the text to be displayed on the right.
The date & timestamp input field is where you can input a date. In the JSON above you can specify the format
value of the output of the date. It allows you to display a formatted date
in browse and read views, using Carbon's formatLocalized()
method
The media picker formfield allows you to upload/delete/select files directly from the media-manager. You can customize the behaviour with the following options:
If you want your users to only be able to upload specific file-types you can do so by passing an object with mime-types to the `allowed` prop, for example:
or
The base_path
and rename
can contain the following placeholders:
{pk}
the primary-key of the entry (only for base_path
)
{uid}
the user-id of the current logged-in user
{date:format}
the current date in the format defined in format
. For example {date:d.m.Y}
{random:10}
random string with N characters
So a base_path
can, for example, look like the following:
A watermark can be added to uploaded images. To do so, you need to define a source
property relative to Voyagers storage-disk. There are a few optional arguments you can use:
position the position where the watermark is placed. Can be:
top-left (default)
top
top-right
left
center
right
bottom-left
bottom
bottom-right
x Relative offset to the position on the x-axis. Defaults to 0
y Relative offset to the position on the y-axis. Defaults to 0
size the size (in percent) of the watermark relative to the image. Defaults to 15
You can generate thumbnails for each uploaded image. A thumbnail can be one of three types:
Fit combines cropping and resizing to find the best way to generate a thumbnail matching your dimensions.
You have to pass width
and can pass height
and position
.
An example for fit
would be:
Crop an image by given dimensions and position. You have to pass width
and height
and can pass x
and y
.
An example for crop
would be:
Resize the image to the given dimensions. You have to pass width
and/or height
.
Some examples for resize
:
The image input has many options. By default if you do not specify any options no problem... Your image will still be uploaded. But, if you want to resize an image, set the quality of the image, or specify thumbnails for the uploaded image you will need to specify those details.
resize If you want to specify a size you will need to include that in the resize
object. If you set either height or width to null it will keep the aspect ratio based on the width or height that is set. So, for the example above the width
is set to 1000
pixels and since the height
is set to null
it will resize the image width to 1000 pixels and resize the height based on the current aspect ratio.
quality If you wish to compress the image with a percentage quality you can specify that percentage in the quality
key. Typically between 70 and 100% there is little notice of image quality, but the image size may be dramatically lower.
upsize This is only valid if you have set your image to be resized. If you specify your image to resized to 1000 pixels and the image is smaller than 1000 pixels by default it will not upsize that image to the 1000 pixels; however, if you set upsize
to true. It will upsize all images to your specified resize values.
thumbnails Thumbnails takes an array of objects. Each object is a new thumbnail that is created. Each object contains 2 values, the name
and scale
percentage. The name
will be attached to your thumbnail image (as an example say the image you uploaded was ABC.jpg a thumbnail with the name
of medium
would now be created at ABC-medium.jpg). The scale
is the percentage amount you want that thumbnail to scale. This value will be a percentage of the resize width and height if specified.
Formfields are the hearth of Voyagers BREAD-system. Each formfield represents a field in your database-table and one input (or output) in BREAD. To tweak your formfields you can insert JSON options which are described in the following pages.
All formfields share a handful options:
All types can include a description in order to help your future self or other users using your Voyager admin panel to understand exactly what a specific BREAD input field is for, this can be defined in the Optional Details
JSON input field:
There are also a few options that you can include to change the way your BREAD is displayed. You can add a display
key to your json object and change the width of the particular field and even specify a custom ID.
The width is displayed on a 12-grid system. Setting it with a width of 3 will span 25% of the width.
The id will let you specify a custom id wrapper around your element. example:
Most formfields allow you to define a default value when adding an entry:
You might want to save an input field into the database as a null
value instead of an empty string.
Simply enough, inside the BREAD you can include the following Optional Details for the field:
This will turn an empty string into a null
value. However you might want to be able to add both an empty string and a null
value to the database for that field. However you have to choose a replacement for the null
value, but it can be anything you wish. For example, if you want a field to change a string (ex. Nothing
) into a null
value you could include the following Optional Details for that field:
Now entering Nothing
into the field will end up as a null
value in the database.
Using the bread builder you may wish to automatically generate slugs of a certain input. Lets say you have some posts, which have a title and a slug. If you want to automatically generate the slug from the title attribute, you may include the following Optional Details:
This will automatically generate the slug from the input of the title
field. If a slug does already exists, it will only be updated if forceUpdate
is set enabled, by default this is disabled.
You can specify a custom view to be used for a formfield.
To do so, you have to specify the view
attribute for your desired field:
This will then load my_view
from resources/views
instead of the formfield.
You get plenty of data passed to your view for you to use:
$action
can be browse
, read
, edit
, add
or order
$content
the content for this field
$dataType
the DataType
$dataTypeContent
the whole model-instance
$row
the DataRow
Developing a custom formfield?
If you are developing a custom formfield and want to customize any of the views, you can do so by merging view
into $options
in your formfields createContent()
method.
When specifying that an input type should be a dropdown you will need to specify the values of that dropdown. In the JSON above you can specify the default
value of the dropdown if it does not have a value. Additionally, in the options
object you will specify the value of the option on the left and the text to be displayed on the right.
A watermark can also be inserted into each thumbnail. Just define the on the parent and set watermark
to true
for each thumbnail you want to insert the watermark to.
Name | Description | Type | Default |
base_path | The start path relative to the filesystem | String | /bread-slug/ |
rename | Rename uploaded files to a given string/expression | String | Original name |
delete_files | Delete files if the BREAD entry is deleted. Use with caution! | bool | false |
show_as_images | Shows stored data as images when browsing | bool | false |
min | The minimum amount of files that can be selected | int | 0 |
max | The maximum amount of files that can be selected. 0 means infinite | int | 0 |
expanded | If the media-picker should be expanded by default | bool | false |
show_folders | Show subfolders | bool | true |
show_toolbar | Shows/hides the whole toolbar | bool | false |
allow_upload | Allow users to upload new files | bool | true |
allow_move | Allow users to move files/folders | bool | true |
allow_delete | Allow users to delete files | bool | true |
allow_create_folder | Allow users to create new folders | bool | true |
allow_rename | Allow users to rename files. Use with caution! | bool | true |
allow_crop | Allow users to crop images | bool | true |
hide_thumbnails | Hides known thumbnails and shows them as children of the parent image | bool | true |
quality | Sets the quality of uploaded images and thumbnails | int | 90 |
allowed | The allowed types to be uploaded/selected. Empty object means all types. Files with other types won't be displayed. | Object | [] |
After running the voyager installer you will see a few new routes that have been added to your routes/web.php
file which look like the following:
This is where the Voyager routes will be rendered. You can change the admin
prefix if you desire, or set any other route configuration you need, such as middleware
or domain
.
When creating a new BREAD type and specifying a slug for that BREAD, you can then visit that route from the following link:
As an example, if we have a products
table and we specified the slug to be products
. You will now be able to visit the following URL:
Notice You may not see a link to your newly created routes or BREAD inside your admin menu. To create a new link in your admin menu visit the documentation for the menu section.
Voyager has a full-fledged Media Manager which allows you to upload files, re-name files, and delete files. You can also add new folders and move files/folders. Basically anything that you would be able to do in any type of Media Manager you can do so in the Voyager Media Manager.
You may also drag and drop files onto the 'upload' button to upload multiple files. The media manager allows you to create thumbnails and add watermarks to uploaded images through the configuration file. Please visit the media-picker documentation to learn about the configuration options.
Notice on File Upload Size
If you are getting an error when trying to upload large files, this may be a setting that needs to be changed in your PHP. Be sure to check max_file_upload
and file_upload_size
Voyager has some awesome database tools which allow you to Add/Edit/Delete or view current database tables. The other cool part of Voyager is that you can add BREAD or (Browse, Read, Edit, Add, & Delete) functionality to any of your tables.
Inside of your admin panel you can visit Tools->Database and you'll be able to view all your current tables in your database. You may also click on 'Create a New Table' to create a new table in your database. All newly created tables will use the charset defined in your default database connection.
If you click the table name you can view the current schema. Additionally you can click on the View, Edit, or Delete buttons to perform that action for that table.
You may also choose to Add BREAD (Browse, Read, Edit, Add, & Delete) for any of your database tables. Once a table already has BREAD you may choose to edit the current BREAD or Delete the BREAD for that table.
Read on further about the BREAD builder in the next section.
With Voyager you can easily create menus for your application. In fact the Voyager admin is using the menu builder for the navigation you use on the left hand side.
You can view your current Menus by clicking on the Tools->Menu Builder button. You can add, edit, or delete any current menu. This means that you can create a new menu for the header, sidebar, or footer of your site. Create as many menus as you would like.
When you are ready to add menu items to your menu you can click on the builder button of the corresponding menu:
This will take you to the Menu Builder where you can add, edit, and delete menu items.
After creating and configuring your menu, you can easily implement that menu in your application. Say that we have a menu called main
. Inside of any view file we could now output the menu by using the following code:
This will output your menu in an unstyled unordered list. If you do use bootstrap to stylize your web app you can pass a second argument to the menu display method telling it that you want to stylize the menu with bootstrap styles like so:
Taking it one more step further you can even specify your own view and stylize your menu however you would like. Say for instance that we had a file located at resources/views/my_menu.blade.php
, which contained the following code:
Then anywhere you wanted to display your menu you can now call:
And your custom menu will now be output.
If you dont want to render your menu but get an array instead, you can pass _json
as the second parameter. For example:
This will give you a collection of menu-items.
The Settings section allows you to add any site wide settings you would like. You can add an image upload setting for your site logo or a text box for the main headline on your homepage.
In this new version you have the ability to add different groups for different settings. So, if you created a new setting inside of the site
group and it had a key of title
you would then be able to reference that setting any where on your site by doing the following:
Or inside of any blade template like:
So, now you can add all kinds of settings in Voyager and reference them in your application.
The Compass section is a quick place for you to go for some link references, font references, run some commands or view some logs.
In the first tab you will see a few link resources and you will see all the fonts that you can use inside of Voyager.
In the Command section you can actually run some artisan commands directly from Voyager.
And Lastly, under the Logs tab you will be able to view all your application logs.
You can override any Voyager routes by writing the routes you want to overwrite below Voyager::routes()
. For example if you want to override your post LoginController:
Voyager has several helper functions that are ready to use. Here you can find the list of available function that may speed up your development.
Voyager will generate thumbnails for Image field type when you specify the .
After you have your thumbnails generated, you may want to display the thumbnails in your view or get the thumbnail URL. In order to do that you need to add Resizable
traits to your model.
Or you can specify the optional image field name (attribute), default to image
As of the latest version you can now add additional CSS and JS files to the voyager master blade without having to copy or modify the blade file itself removing potential manual migration headaches later on. The CSS and JS files are added after any Voyager assets so you can override styles and functionality comfortably.
This is all handled via the voyager.php
config file:
The path will be passed to Laravels function.
You can override any of the BREAD views for a single BREAD by creating a new folder in resources/views/vendor/voyager/slug-name
where slug-name is the slug that you have assigned for that table. There are 4 files that you can override:
browse.blade.php
edit-add.blade.php
read.blade.php
order.blade.php
Alternatively you can override the views for all BREADs by creating any of the above files under resources/views/vendor/voyager/bread
You can override the submit button without the need to override the whole edit-add.blade.php
by extending the submit-buttons
section:
You can override the controller for a single BREAD by creating a controller which extends Voyagers controller, for example:
After that go to the BREAD-settings and fill in the Controller Name with your fully-qualified class-name:
If you want to override any of Voyagers core controllers you first have to change your config file config/voyager.php
:
Then run php artisan voyager:controllers
, Voyager will now use the child controllers which will be created at App/Http/Controllers/Voyager
You are also able to override Voyagers models if you need to. To do so, you need to add the following to your AppServiceProviders register method:
Where name is the class-name of the model and object the fully-qualified name of your custom model. For example:
The next step is to create your model and make it extend the original model. In case of DataRow
:
Voyager comes with Roles and Permissions out of the box. Each User has a Role which has a set of Permissions.
Inside of the dashboard you can choose to Add, Edit, or delete the current Roles. Additionally when you click to edit a particular role you can specify the BREAD permissions.
New in version 1.0, we've changed Voyager's authorization system to be ! This means that you can check for permissions in the following ways:
Out of the box there are some permissions you can use by default:
browse_admin
: Whether or not the user may browse the Voyager admin panel.
browse_database
: Whether or not the user may browse the Voyager database menu section.
browse_bread
: Whether or not the user may browse the Voyager BREAD menu section.
browse_media
: Whether or not the user may browse the Voyager media section.
browse_menu
: Whether or not the user may browse the Voyager menu section.
browse_settings
: Whether or not the user may browse the Voyager settings section.
read_settings
: Whether or not the user can view or see a particular setting.
edit_settings
: Whether or not the user can edit a particular setting.
add_settings
: Whether or not the user can add a new setting.
delete_settings
: Whether or not the user can delete a particular setting.
Additionally you can Generate permissions
for every BREAD type you create. This will create the browse
, read
, edit
, add
and delete
permission.
As an example, perhaps we are creating a new BREAD type from a products
table. If we choose to Generate permissions
for our products
table. Our permission keys will be browse_products
, read_products
, edit_products
, add_products
and delete_products
.
Notice
If a menu item is associated with any kind of BREAD, then it will check for the browse
permission, for example for the Posts
BREAD menu item, it will check for the browse_posts
permission. If the user does not have the required permission, that menu item will be hidden.
You can also check for permissions using blade syntax. Let's say for instance that you want to check if a user can browse_posts
, simple enough we can use the following syntax:
Or perhaps you need to run an else condition for a permission. That's simple enough:
Couldn't be easier, right ;)
Voyager supports multiple languages for your models.To get started, you need to configure some things first.
First you need to define some locales
in your config/voyager.php
file and enable
multilanguage:
After that you need to include the Translatable
Trait in your model and define the translatable attributes:
Now you will see a language-selection in your Pages BREAD.
If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.
If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass in your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.
This will update or create the translation for title of the post with the locale da. Please note that if a modified attribute is not translatable, then it will make the changes directly to the model itself. Meaning that it will overwrite the attribute in the language set as default.
To search for a translated value, you can use the whereTranslation
method.
For example, to search for the slug of a post, you'd use
whereTranslation
accepts the following parameter:
field
the field you want to search in
value
the value you want to search for
locales
the locales you want to search in as an array. Leave as null
if you want to search all locales
default
also search in the default value/locale. Defaults to true.
You can now override all methods from the
operator
the operator. Defaults to =
. Also can be the value (Same as )
If you want to customize TinyMCE within Voyager, you can do so by adding a additional JS file to your config.
In this file you have to define a function like
If you need to manipulate TinyMCE before it was initialized, you can use
Now you can control the TinyMCE instance(s) on the page. For all possible variables and functions, please refer to the TinyMCE documentation.
Sometimes you want to format an attribute only for one (or some) of the BREAD-actions.
For example if you have a name
field and on the browse-page you want to display something when the field is empty, you define the following in your model:
This will display "Empty" if the actual field is empty, or return the value if not.
Likewise you can do the same for the other BREAD-actions:
This is only to assist with enabling soft-deletion for your models within Voyager. Please refer to the Laravel documentation for specifics.
When creating a table using the Database Manager you've selected the 'Add Soft Deletes' button and then when adding the BREAD functionality to that table you've added a Model Name, you only have to edit your Model file to fully enable Soft-Delete on that table.
A default model will look like this:
Just turn it into:
And from now on, every time you delete a record from that table, it won't actually be deleted, only the deleted_at
column will be written with the current timestamp.
With Voyager 1.1 you are able to define additional attributes which you can show in a relationship.
For example a Post
has an Author
and you want to display the Users
full-name. To do so, we first need to define an Accessor
After that we need to tell Voyager that there is an accessor we want to use:
Thats it! You can now select full_name
in your Relationship.
You can easily add a new Formfield to Voyager. In the example below we will add a number form field (which is already included by default in Voyager).
First we create a new class in our project (it doesn't matter where it is placed) called NumberFormField
The codename
variable is used in the dropdown you see in the BREAD builder. In the createContent
method we are returning the view that is used to display our form field.
Next, we will create the view specified above.
In the view we can add whatever logic we want.
When we are done with our view, we will tell Voyager that we have a new form field. We will do this in a service provider (in the example below we use the AppServiceProvider
.
With Voyager you are able to store coordinates and select them from a map.
To do so, you first need to make sure that the column in your table is either GEOMETRY
or POINT
.
After that you have to include the Spatial-Trait in your Model and define the column:
Now you can go to the tables BREAD-settings and set your field to be Coordinates
.
After that you will get a Map where you can select your Coordinates.
Make sure to set the Google Maps API-Key in your configuration. This is also the place where you can define the default location of your map.
You can get the coordinates from your model by calling
This will return an array of coordinates with lat
as the latitude and lng
as the longitude.
Starting with Voyager 1.2 you can define a (custom) guard which is used throughout Voyager.
To do so, just bind your auth-guard to VoyagerAuth
.
Open your AuthServiceProvider
and add the following to the register method:
Now this guard is used instead of the default guard.
Symptom: You get an error page saying
Cause: There are two possible causes:
1. You dont have a primary-key for your table
2. You have a primary-key but it's not called id
Solution: As there are two causes, there are also two solutions: 1. Simply create a field id
for the table
2. Tell your model about your primary-key: protected $primaryKey = 'your_primary_key';
Please consider following
Symptom: When visiting your site with HTTPS, images within Voyager fail to load.
Cause: Images urls are generated by Voyager using
If voyager.storage.disk is set to public, and the public disk is the default from Laravel, then the url property in the disk configuration is set to
which uses the non-HTTPS APP_URL value to build an absolute url to the image.
Solution: If you remove env('APP_URL'). from the public disk configuration, then it will render a domain-relative url, which will always use the current domain and protocol.
As an aside, if you need a fully-qualified URL, you could wrap the call to Voyager::image('...')
with asset()
, so it would be
This will return the current protocol, domain, and correct path to that image.
Action buttons are displayed when browsing a BREAD next to each row
You can add your own buttons very easily. First we will create an Action-class which extends Voyagers AbstractAction in app/Actions/MyAction.php
Next we need to tell Voyager that we want to use this action. For this open your app/Providers/AppServiceProvider.php
and search for the boot()
method
If you only want to show your action for special datatypes you can implement a function shouldActionDisplayOnDataType()
in your action:
Mass actions are called for multiple instances of a model. If you want your action to be a mass action, just implement the following method:
After that you will see your new button when browsing any BREAD