Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Code Block Laravel Package

mrshanebarron/code-block

mrshanebarron/code-block is a Laravel/PHP package for defining, managing, and rendering code blocks in your application. It provides a simple, reusable approach to keeping formatted code snippets organized and displaying them consistently across your views and content.

View on GitHub
Deep Wiki
Context7

mrshanebarron/code-block is a lightweight Laravel package for rendering clean, syntax-highlighted code blocks directly in your Blade views. Drop in the provided component or directive and your snippets are automatically escaped, highlighted, and styled—no manual markup required.

  • Blade component and directive for one-line embeds
  • Automatic syntax highlighting with configurable themes
  • Line numbers, copy-to-clipboard button, and language labels
  • Publishable config and views for full customization
  • Works with inline and multi-file snippets
Frequently asked questions about Code Block
How do I install mrshanebarron/code-block in a Laravel application?
Install it with Composer using composer require mrshanebarron/code-block. The package follows the standard Laravel service-provider pattern, so its provider should be auto-discovered and no manual registration is normally required. After installing, run composer dump-autoload and php artisan optimize:clear so config, route, view and application caches pick up the new package. Pin the version explicitly, for example 1.0.2, rather than floating on ^1.0 if you want the naming fix to land deliberately.
Which Laravel and PHP versions does code-block support?
The supported PHP and Laravel majors are declared in the package composer.json, so check that file before adding it to an older application. The 1.0.2 patch release announced no new dependencies and no raised requirements, but patch releases occasionally ride on a raised version floor. Confirm your PHP floor and Laravel major match the constraints, then run your test suite on a case-sensitive Linux runner, because naming-related fixes can behave differently on macOS or Windows filesystems.
How do I render a code block in a Blade view with this package?
Code-block is a Laravel UI component package, so rendering happens in your views rather than in controllers or routes. You define or pass a snippet and render the component in Blade wherever the example should appear, such as documentation pages, admin panels, or marketing docs. Check the repository README for the exact component tag and prop names, since the public API is what determines whether you use a Blade component tag or a helper call.
Does the package handle syntax highlighting automatically?
The package is described as rendering customizable, syntax-highlighted snippets, so highlighting is part of its rendering layer rather than something you assemble by hand. What is not stated is whether highlighting is produced server-side or requires front-end assets such as a CSS theme or JavaScript library. Verify that detail in the README before shipping, because it affects whether you need to publish assets or add a stylesheet to your layout.
Do I need to publish config or view files after installing code-block?
The 1.0.2 release announced no config publish step and no migrations, so a plain composer require should be enough to get started. If the package does ship publishable views or stubs, run php artisan vendor:publish with the appropriate tag to copy them into your application. If you already published artifacts under version 1.0.0 or 1.0.1, republish or regenerate them so they match the corrected class naming.
What changed in code-block 1.0.2 and does it affect my code?
Version 1.0.2 fixed PHP class naming so hyphenated identifiers are converted to PascalCase. That points to a convention layer that derives PHP class names from hyphenated slugs, which may cover class names, file paths, route names, or container keys. If you generated or scaffolded classes under 1.0.0 or 1.0.1, those artifacts may no longer resolve, so regenerate them in a clean working tree and diff the result before merging.
Why do I get class not found errors after updating code-block on Linux?
Case-only renames are a classic failure mode: Git on macOS or Windows may not register a rename from my-thing.php to MyThing.php because those filesystems are case-insensitive. The deploy then carries the wrong casing, and PSR-4 autoloading fails on case-sensitive Linux with a class not found error. Deploy from a clean checkout rather than an incremental sync, run composer dump-autoload, clear config, route, view and application caches, and restart PHP-FPM or workers to flush OPcache.
Can I customize how code blocks look in my application?
The package is positioned around customizable, reusable code blocks, which typically means styling is controlled through component props, published views, or CSS classes you own. Start by checking whether views or a config file are publishable, since that determines where overrides belong without touching vendor files. Keep customizations in your own stylesheet or published view copies so a composer update does not overwrite them.
How should I test code blocks in a Laravel test suite?
Render the component inside a feature test and assert that the expected snippet output appears in the response, including that code is escaped rather than executed. Run the suite on a case-sensitive Linux runner with a freshly installed vendor directory and cleared caches, which is the configuration that catches naming and autoload issues. If you generate code block classes, add a test that regenerates them and compares output so future naming changes fail loudly.
What are the alternatives to mrshanebarron/code-block for syntax highlighting in Laravel?
Common alternatives are dedicated highlighting engines such as Prism, highlight.js, or Shiki wired into Blade, or other Laravel Blade component packages that bundle pre-styled code blocks. Weigh how much you want handled server-side versus in the browser, whether you need copy buttons and line numbers, and how much CSS you are willing to maintain. Also compare maintenance activity and declared Laravel version support, since a small package with an unclear support matrix is a long-term risk in production.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package