How to Create CMS with Laravel Nova

Jaymine Shah
Techcompose
Published in
4 min readDec 3, 2018
Laravel Nova

Nova is administration panel for Laravel application development that designed with a clean and beautiful design. Nova is powered by Vue.js, Vue Router, and Tailwind.css which is powerful and flexible to build custom tools, cards, and fields. Nova is configured entirely using simple PHP classes; configuration is not stored in the database. Pricing of Nova is $99 per site for a solo license and $199 per site for Businesses & Teams with a pro license. Once you have a license you will download nova files and install it with the composer. Although it’s worth to use the license as it provides awesome features.

There is plenty of CMS available in the market like WordPress, Magento, Joomla etc. So here are the reasons to use laravel CMS:

  1. It’s very effective and lightweight content management.
  2. It’s not necessary to learn any CMS
  3. Purely object-oriented
  4. Easy to customize

So Nova is perfectly suitable for lightweight CMS, but it can’t use to build complex CMS because it takes a lot of efforts. By using nova user can easily perform CRUD operations as well searching and filtration of data. Let’s see the topics provide nova:

  1. Resource
  2. Fields
  3. Actions
  4. Filters
  5. Lenses
  6. Search
  7. Metrics
  8. Authorization

1. Resource:

The resource is the backbone of the Nova, each of resource has its own class. As simply we can say the resource is list page, detail page, and an edit/create page.

namespace App\Resources;use App\User;
use Illuminate\Nova\Resource;
class UserResource extends Resource { protected $model = User::class; public function fields() {
return [
ID::make()->sortable(),
Text::make('Name')
->sortable()
->rules(['required']),
Gravatar::make(),
];
}
}

2. Fields:

There are many types of fields like Text, ID, Date, etc… As well you can also build your own custom field and you can use it in your resource. Many of fields are sync column in a database, for a Text shows an <input> and matches to a VARCHAR data type. It’s about a single UI item, but there are some fields that have one UI element for multiple columns/UI elements. So these type of fields might not have database columns.

Some of the field types:

  • ID
  • Text
  • Textarea
  • Password
  • Boolean
  • Markdown
  • Trix
  • Code (with customizable properties about which language you’re working with for syntax highlighting)
  • DateTime (with a super slick picker)
  • Date (with a super slick picker)
  • BelongsTo
  • HasMany
  • MorphMany
  • ManyToMany etc.
  • File — customize the disk, store the original name, store size etc.
  • Image — like the file, but with image previews and thumbnails
  • Avatar-like image, but shows next to the item in search results
  • Video
  • Gravatar
  • Place
  • Country

Place fields:

function location() {
return [
Text::make('Address'),
Text::make('City'),
Text::make('State'),
Text::make('Zip'),
Country::make('Country'),
];
}

Formatting fields

Text::make('File', 'file', function ($value) {
return number_format($value / 1024, 2) . 'kb';
});

Modification

function customization() {
return [
Text::make('Zipcode')
->rules(['required'])
->creationRules(['rules here'])
->updateRules(['rules here'])
];
}

3. Actions:

Actions are classes that used in for perform task on a collection of items. To add an action into your class, just use actions() method on your resource, and return your actions in there:

class NewActionResource {    // ...
public function actions() {
return [
new Actions\Publish,
];
}
}

4. Filter:

Filters are quite similar to actions; as they are defined as simple PHP classes that enable you to scope your queries with the query builder. Filters are shown up in a drop-down on the index page and let you show only items that match this filter. As similar to action, the filter defines with filter() method:

class NewFilterResource {    // ...
public function filters() {
return [
new Filters\PublishedPosts,
];
}
}

5. Lenses

Lenses allow you to customize or build different views for a resource with full control over the underlying query and fields returned. Lenses can be used in the resource’s index page when it’s defined.

You can also use fields() and filters() and actions() methods on your Lens class, just like on resources.

6. Metrics

There are three standard metrics,

  1. Value Metrics: To make the value metric,
  2. Trend Metrics: To make the trend metric,
  3. Partition Metrics: To make the third type of pie graph, modify your trend metric.

All three metrics makes easy to generate a custom matrix for your application. It will available in resource view of the index, while you define on a resource.

7. Authorization

Nova integrated with laravel authorization policies. Nova resources automatically leverage your existing application policies to determine a user’s abilities. Nova takes a simple approach to authorization that leverages many of the laravel features you are already familiar with.

Contact Laravel Development Company to develop your Business mobile app or web application with elegant design. Contact us to Hire dedicated Laravel developer today or reach us at inquiry@techcompose.com for any assistance regarding larval development requirement.

--

--