Add a blog to your Laravel Application with Hyvor Blogs

add-a-blog-to-your-laravel-application-with-hyvor-blogs

Hyvor Blogsย is a simple and powerful blogging platform. In this tutorial, we will see how to create a blog with Hyvor Blogs and host it in an existing Laravel application’sย /blogย route. All contents of the blog will live inside a cache store in your application, which you can customize. We will use webhooks for cache invalidation.

Part 1: Set up Hyvor Blogs

In this part, we will create a blog and configure the basic settings needed for self-hosting.

  • First, create a blog at theย Hyvor Blogs Console. You will get a subdomain, which you need in the next step.

  • Go toย Settings โ†’ Hosting

    • Updateย Hosting on/atย toย Self-hosting
    • Set theย Self-hosting URLย to the absolute URL of your Laravel application’s blog route. For this tutorial, set it toย https://mywebsite.com/blog. You can customize theย /blogย route later if needed.

      Note: To test webhooks, this URL should be publicly accessible. Therefore, if you are testing locally, we recommend using a tool likeย ngrokย to expose your Laravel site temporarily on the internet.

    • Click Save

      Hosting setting up in Hyvor Blogs Console

  • Go toย Settings โ†’ API Keys

    • Click CREATE

      • Set a name (ex: “For Laravel Blog”)
      • Selectย Delivery APIย as the API
      • Create API Key

      Creating an API key

This API key will be needed in the next step.

  • Go toย Settings โ†’ Webhooksย and create a Webhook with the following values.

    • URL: Set this to “your website URL + /hyvorblogs/webhook”. Ex:ย https://mywebsite.com/hyvorblogs/webhook
    • Select the following events

      • cache.single
      • cache.templates
      • cache.all

You will need theย Webhook Secretย in the next step.

Part 2: Set up Laravel Application

In this part, we will set up your laravel application to “communicate” with Hyvor Blogs APIs/Webhooks to render your blog correctly.

First, install theย hyvor/hyvor-blogs-laravelย Laravel package in your project using composer.

composer require hyvor/hyvor-blogs-laravel

Then, run the following command to generate the config file.

php artisan vendor:publish --provider="HyvorHyvorBlogsHyvorBlogsServiceProvider" --tag="config"

This command will copy the default configuration file toย config/hyvorblogs.phpย in your application, where you will be configuring the blog.


return [
    'blogs' => [
        [
            'subdomain' => '',
            'delivery_api_key' => '',
            'webhook_secret' => null,
            'route' => '/blog',
            'cache_store' => null,
            'middleware' => [],
        ],
    ],
];

blogsย key contains an array of blog configurations. It allows you to set up multiple blogs in the same Laravel application. Let’s configure a blog.

  • Setย subdomainย to the subdomain of the blog, you created in the first step. You can get it toย Console โ†’ Settings -> Hosting.

  • Setย delivery_api_keyย to the Delivery API key, you created earlier atย Console โ†’ Settings -> API Keys

  • Setย webhook_secretย to the secret you got atย Console โ†’ Settings -> Webhook

  • Setย routeย to the base path of your blog within the Laravel application. If you change this, make sure to update the Hosting URL in the Console.

  • (optional) Setย cache_storeย to use a customย cache storeย to cache your blog.

  • (optional) If you need to add any additional middleware, use theย middlewareย array.

Now, try visiting theย /blogย path of your blog. If everything is fine, your blog should be displayed there. Try updating a post to make sure webhooks are working.

Finally

  • If you have any troubles, comment below or contact support.

  • If you would like to know how this works internally, see ourย self-hosting with web frameworksย documentation.

  • Once you have set up everything, you can customize your blog theme and start writing. Ourย documentationย has all the information you need.

  • If you like to set up multiple blogs within the same applications, you can add more configuration arrays to theย blogsย array in the config file.

  • Any problems with the Laravel package? Raise an issue or contribute atย Github.

This article was original published on our blog.

Total
1
Shares
Leave a Reply

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

Previous Post
15+-organizational-skills-every-leader-needs-[+-ways-to-develop-them]

15+ Organizational Skills Every Leader Needs [+ Ways to Develop Them]

Next Post
sveltekit-changes:-routes

Sveltekit Changes: Routes

Related Posts