How to use Roots Radicle with Laravel Herd | Tom McFarlin

How to use Roots Radicle with Laravel Herd | Tom McFarlin

1 minute, 37 seconds Read

I have previously written about the use of Laravel Herd as my favorite PHP development environment. Outside of my daily work I also work with one couple by friends On a project with an iOS app who talks with a rest API through Headless WordPress Backend.

The Web app was built using a set of tools from Carrots included Jet:

Radicle is a strange starting point for WordPress projects with the root pile.

In short, Radicle allows us to use Laravel functions in WordPress. But one of the challenges with my setup is to make Laravel Herd and Radicle actually work.

It appears that the solution is not that difficult. And if you are in a similar situation, you can work here with Radicle with Laravel Herd.


Roots Radicle with Laravel herd

Project setup

Firstly, I work under the assumption that you have your project already linked and secured with herd.

In our case we use a monorepo that contains both the iOS app and the web application. The web app is located in projects/monorepo-name/apps/wordpress. So I spent the usual commands, add that to the herd.

Second, I have the .env Figure configured so that it has all the necessary information for the database, various WP Environment variables, saltAnd other information needed to get up the web app.

The actual problem

Thirdly, and this was the most problematic, I had to add an adapted driver with whom Radicle could work with Laravel Herd. The path to adapted drivers on your machine can vary, but if you perform the latest version of macOS and have not adjusted the herd installation, then should have to Looks like something:

/Users/yourname/Library/Application Support/Herd/config/valet/Drivers

Note that if the Drivers Directory does not exist, make it. Than touch A file with the name RadicleValetDriver.php In that folder and add the following code (you don’t have to change anything of it):

isActualFile($staticFilePath)) {
            return $staticFilePath;
        }

        return false;
    }

    /**
     * Get the fully resolved path to the application's front controller.
     */
    public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
    {
        $_SERVER = $uri;
        if (strpos($uri, '/wp/') === 0) {
            return is_dir($sitePath.'/public'.$uri)
                            ? $sitePath.'/public'.$this->forceTrailingSlash($uri).'/index.php'
                            : $sitePath.'/public'.$uri;
        }

        return $sitePath.'/public/index.php';
    }

    /**
     * Redirect to uri with trailing slash.
     *
     * @return string
     */
    private function forceTrailingSlash(string $uri)
    {
        if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
            header('Location: '.$uri.'/');
            exit;
        }

        return $uri;
    }
}

Note that this will be performed at PHP 8.4, so you may need to adjust your function signatures and other functions if you run on a considerably lower version (although I have not really tested the thing lower than 8).

Once ready, you must be able to load your project in the web browser. If this is not the case, restarting the services of Herd must succeed. And, to the off you change still Have a mistake, the stacking must be simple enough to follow to see where the problem lies.

Given a vanilla herd set up and radicle integration with your WordPress project, this custom driver must be everything you need to make everything work with as little effort as possible.

Remark: This was adjusted directly from the Laravel broncode that you can find on Github.

#Roots #Radicle #Laravel #Herd #Tom #McFarlin

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *