Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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:
And then run
Next, you may want to be sure that you have all the latest published assets. To re-publish the voyager assets you can run the following command:
Lastly, you may wish to clear your view cache by running the following command:
Welcome to the Voyager documentation for version 1.0. 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.
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.
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
With the installation of voyager you will have 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. Following is a more detailed description of each of the configuration sets:
User Config
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.
Controller Config
You can specify the default controller
namespace of voyager so 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.
If you do only wish to overwrite a single controller, you might consider adding the following piece of code in your
AppServiceProvider
'sregister
-method:
Model Config
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.
Asset Config
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.
Note: 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.
Storage Config
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.
Database Config
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.
Prefix Config
In this config you can specify an alternate prefix for visiting voyager. Instead of visiting /admin
perhaps you want to visit /backend
to visit the voyager admin.
Multilingual Config
Thanks to all the contributors to voyager we now have multilingual support.
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)
Dashboard Config
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
.
Primary Color Config
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.
Show Dev Tips Config
In the Voyager admin there are dev 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 to false.
Additional CSS Config
This is super cool, 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.
Additional JS Config
The same goes for this configuration. You can add your own javascript that will be executed in the Voyager admin dashboard. Add as many js files as needed.
Google Maps Config
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 map 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 call also be added to your .env file.
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.
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 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 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:
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:
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
.
You can override any of the BREAD views by creating a new folder in resources/views/vendor/voyager/slug-name
and slug-name will be the slug that you have assigned for that table. There are 2 files that you will include in each which will be:
browse.blade.php
edit-add.blade.php
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.
When Editing Your Browse, Read, Edit, Add, and Delete Rows you have a select box that allows you to include additional details or options for your datatype. This textarea accepts JSON and it applies to the following types of inputs:
Text (Text Box, Text Area, Rich Textbox and Hidden)
Check Box
Drop Down
Radio Button
Image
Date
Find out how to use these additional details below:
Text Box, Text Area, Rich Textbox and Hidden are all kind of texts inputs. In the JSON above you can specify the default
value of the input.
In Voyager a Check Box 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.
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.
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 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.
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
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:
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 or required and max length of 12
Additionally, you may wish to add some custom error messages which can be accomplished like so:
Since v0.10.13
you can do the required
and max:12
rule the following way:
You can find a list of all available validation rules in the Laravel docs.
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.
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.
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.
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:
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.
Update your Composer.json
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:
And then run composer update
Run the necessary migrations
You will now need to run the following migrations to include new tables or rows that have been added to the latest version. you can find each of these migrations below:
(possibly need this migration, if already exists do not include) https://github.com/the-control-group/voyager/blob/v0.11.14/publishable/database/migrations/2017_04_21_000000_add_order_to_data_rows_table.php
You can do this by adding each of those migrations to your database/migrations
folder and then run php artisan migrate
Upgrading Settings
Only applicable if you are using settings in your application. New to version 1.0, settings are grouped by section. For instance the following setting will not work:
Each setting key will now belong to a group. Which means that you would need to change the setting to:
{{ setting('site.title') }}
And that title key would now need to have a group with the name of 'Site', like the following:
To update all the settings in your app, you may want to, just create a group name, such as Site, and then update all your settings to include the site
prefix:
Any previous Admin settings have been added to a group called 'Admin'.
Final Steps
Next, you may want to be sure that you have all the latest published assets. To re-publish the voyager assets you can run the following command:
Then you may wish to clear your view cache by running the following command:
At last, must change your User
model to extend TCG\Voyager\Models\User
And now you'll be upgraded to the latest version.
If you're planning to use hooks If you want to use Hooks (Voyager's built-in plugin system) you must run php artisan hook:setup
before it will work. This is now included in php artisan voyager:install
, so this will only need to be run after upgrading from an earlier version.
Troubleshooting
Be sure to ask us on our slack channel if you are experiencing any issues and we will try and assist. Thanks.
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.
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.
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 more in line with Laravel! This means that you can check for permissions in the following ways:
You may also choose to use the Voyager facade and pass the permission as a string:
The value of each check will return a boolean whether or not the user has that certain permission. However you might wish to throw a forbidden exception if the user does not have a certain permission. This can be done using the canOrFail
method:
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 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.
Then you can call the thumbnail function in your view or anywhere you like.
Or you can specify the optional image field name (attribute), default to image
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.
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:
This is only to assist with enabling soft-deletion for your models within Voyager. Please refer to the 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.
You can use your own Controller by extending Voyager's Controllers. To do it, first define your controller Namespace at 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
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, if you have not started with a fresh install of 0.11.10+
you will need to manually add this to your config.
You may want to look at the /vendor/tcg/voyager/publishable/config/voyager.php
to see the config layout and check for any missing options.
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.