8 min read

Building a Secure Laravel Document Management System with Laravel Nova

Interested in generating passive income? Join our partnership program and receive a commission on each new client referral. Learn more.

In one of our projects, we had to find a way to securely store and manage a lot of documents in PHP. After exploring a few options, our developer developed a robust and secure Laravel document management system using Laravel Nova.

But before we get to the specifics of the management system and how it works, you probably need a bit more context into the problem we were facing. So, let’s walk through the product first and go from there.

About The Project

Laravel document management system

The platform is designed to facilitate connections between investors and investment holders; it’s a time-saving solution that simplifies the process of exchanging crucial investment documents. This exchange typically happens via email or through physical paperwork, which can further slow things down. But as time is always a scarce resource, any delays can be highly frustrating for all parties involved.

Security is also a major concern when it comes to sharing documents. You want to maintain full control over your sensitive files and ensure that they don’t fall into the wrong hands. On the other hand, users should be able to see those documents comfortably.
It’s essential to be able to store and deliver documents safely and to protect them from being leaked to third parties or causing harm to your company. However, the more individuals involved in document sharing, the higher the potential for data leaks and security breaches.

The platform provides a comprehensive solution to all document management challenges. It allows you to store documents securely, control who can access them, manage team members effectively, and enjoy a comfortable and reliable working environment. It saves time, guarantees document security, and makes the entire process much more enjoyable.

Dealing with large-scale systems can be an immense responsibility. In this project, we encountered various challenges, and we would like to take a moment to discuss some of these hurdles with you.

Laravel Document Management System

Managing documents was one of the most crucial things to handle. At first, we thought it would be great to use a ready-to-use solution – Filestack, since it provides robust document management features, including watermarking, permissions, reliable security, etc.

After carefully planning our goals, we decided to use an open-source library that might save time in building a document management system. Having had prior experience with Laravel Nova File Manager, we thoroughly assessed its architecture, reliability, and scalability against our requirements. Unfortunately, we realized that adapting it to suit our specific needs would consume more time than we anticipated, outweighing any potential time-saving benefits. Therefore, we decided to develop our own file management system that included everything we needed.

Document delivery was the most essential aspect of this project. We wanted to deliver PDF files that were not only password-protected and encrypted but also watermarked with unique credentials such as the user’s email and time of download. So our team took charge of the whole document management process.

After researching available packages, we found that there are not many robust libraries for PDF management in PHP. Of course, libraries like TCPDF can create PDFs, but if you want to load an existing PDF, modify it, and save it, you will need to spend a few hours researching how to do it.

So, we discovered a library known as “FPDI,” which proved to be an ideal solution for our needs. This library uses “TCPDF” to handle PDF files. As we know, there are different versions of PDFs that have evolved since Adobe was created. The free version of the “FPDI” library only supported PDF version 1.5, which is insufficient for a production environment. “Setasign,” the creator of this library, provides a paid version of the library that can support newer versions of PDF. With this library, we successfully built a complex and secure document delivery system.

This library makes it incredibly simple to set password protection for specific actions on a PDF. For instance, take a look at how easy it is to implement:

$pdf->SetProtection(
    ['modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble'],
    $password, null, 3
);
return $pdf;

Laravel Nova – Custom Resource Tools

In order to deliver the product within the deadline, we wanted the quickest, most reliable, and most secure way to build an admin panel. We had to choose between Backpack and Nova. We were drawn to Backpack for its flexibility, excellent support, and well-documented functionality.

In contrast, although Laravel Nova 4 may not be as scalable as Backpack, it offers a faster development process. Moreover, in the event of any difficulties, it was possible to build custom functionality using Vue.js (Nova Custom Resources). So we decided to choose Nova.

Now that the project is finished, it has become apparent that our decision was indeed the right one. In fact, we implemented really complex logic in a record-low time. One of the tools that we wanted to build was a frontend for file management. As we’ve already mentioned, we needed to establish a method for handling custom logic from the frontend side.

So, we created the boilerplate of the Vue.js app and started working on it.

php artisan nova:resource-tool nova-tools/file-management

One aspect we find less than desirable about this process is that it uses Laravel Mix to build a front-end app. As we know, Vite is a much faster, newer tool for creating Vue.js apps. So, of course, we modified the files to continue working on Vite.

In package.json, we replaced the scripts:

"scripts": {
    "dev": "vite",
    "build": "vite build",
    "watch": "vite build --watch",
    "nova:install": "npm --prefix='../../vendor/laravel/nova' ci"
},

Removed Laravel mix javascript file, added vite.config.js, configured it, and everything started working as expected: way faster and more comfortable.

Documenting Code: Laravel Scribe

When we started working on this project, we began to document our code using the OpenAPI (formerly known as Swagger) specifications. It is a powerful and flexible method to document code, but it took too much time to document everything. We had tight deadlines, so we thought there should be other ways to do the same documenting job much faster.

Our team leader suggested using Laravel Scribe. After reviewing it, we all agreed that this was exactly what we needed.

One of the standout features of Laravel Scribe is its ability to automatically generate documentation for all endpoints and create Swagger and Postman projects that can be easily imported into the software. This modern tool not only saves time but also provides a more intuitive and user-friendly way of documenting your code. So if you haven’t used Laravel Scribe before, we highly recommend giving it a try.

The Final Thoughts

We’ve discussed the technical aspect of the process quite thoroughly, so I think the only other takeaway from here is that when working on a large system, you will definitely come across challenges you’ve never encountered before and, if you’re lucky, you’ll be on a tight deadline.

But as long as you learn from the community, constantly search for novel solutions and try them, you will craft superior solutions. In our case, we were struggling with writing documentation; it was taking too long. So we kept digging and found Laravel Scribe, which turned out to be a lifesaver. Then, since we were on a deadline, we implemented Laravel Nova, which immensely cut down our time frame. That’s all for now, folks; keep moving forward! 

Meet the authors

We are a 200+ people agency and provide product design, software development, and creative growth marketing services to companies ranging from fresh startups to established enterprises. Our work has earned us 100+ international awards, partnerships with Laravel, Vue, Meta, and Google, and the title of Georgia’s agency of the year in 2019 and 2021.

Contact us