This tutorial focuses on how to get things setup in Laravel using Composer.
I've been releasing some of my code as open source packages, and looking to extend
Laravel Nova. One annoyance of this is I like to keep my folders tidy,
and I want to be able to develop the open source component as part of an existing website. Additionally,
I'd like to be able to just quickly edit this in a dedicated folder of my project rather than having to navigate to the vendors
directory of my project
I primarily develop natively on a Windows 10 machine at the moment. Windows 10 has a nice symlink feature available in PowerShell, which allows us to create a fake directory inside of our existing website, which points to another folder on our computer.
This is a quick and easy thing to get setup, and saves some time while keeping your folders organized.
Powershell offers a cmdlet called New-Item
which lets us create a new file or directory, and takes in a few parameters. You may need to start PowerShell with administrator privileges if you are
using a version older than Windows 10 Build 14972
, or don't have Developer mode enabled.
In the case of Laravel Nova, we want to create a symbolic link in the nova-components
directory. Navigate to that directory in your
Powershell terminal before running this command.
new-item -itemtype symboliclink -path . -name YourPackageNameHere -value C:\Absolute\Path\To\Your\Component
That directory should now show up in your nova-components
folder, or where ever you are storing your symbolic link.
Next, tell composer that you have a dependency of this folder. When you run composer install
or composer update
it will look in this folder
to see if there is any composer configuration which provides
a repository you're looking for.
Add or modify the repositories
key in your composer.json
file
"repositories": [
...
{
"type":"path",
"url": "./nova-components/YourPackageNameHere"
}
],
Next, tell composer that you want to install a package from that directory by modifying your require
or require-dev
key, where the name is what you specified in your packages composer.json
file.
"require": {
...
"yourvendorname/yourpackagename": "*"
},
Options for releasing this, for example, when you merge into your master branch, are to replace the repositories item you added, which will
try and discover the package from packigest, or pointing the repository url key to your GitHub, and changing the type key to vcs
.
Because this package is managed in another repository, I just want to make a quick note; when I set this up, I often add a line in my .gitignore to ignore this folder.
...
/nova-components/YourPackageNameHere
There are many different ways to solve this problem. In Linux, this is much easier to do as symbolic links have been around forever, but in Windows, that isn't the case.
With the introduction of the symboliclink
type to new-item
, I'm able to set up my folders in a way I enjoy.
Please let me know if you have any questions or comments about this article on Twitter or in the comments section.
I am a developer who is currently living in Ho Chi Minh City, Vietnam. I work with Laravel, VueJS, React, and other technologies in order to provide software to companies. Formerly a Microsoft Dynamics consultant.