定制 wallacemaxters/laravel-navalha 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wallacemaxters/laravel-navalha

Composer 安装命令:

composer require wallacemaxters/laravel-navalha

包简介

A small library to transform your laravel in alpinejs template

README 文档

README

🇧🇷🇧🇷🇧🇷🇧🇷🇧🇷🇧🇷🇧🇷🇧🇷🇧🇷🇧🇷🇧🇷

Navalha (is a joke with "Razor" name in portuguese) is a small framework written for Laravel, which allows binding of Laravel data on the server-side to AlpineJS variables.

How to Install

Run the follow command to install Navalha.

composer require wallacemaxters/laravel-navalha

And publish assets

php artisan vendor:publish --tag=navalha-assets

Now, your need to add @navalhaStyles and @navalhaScripts in the <head> tag of your template.

Generate a Component

php artisan navalha:make-component Products

This command will generate resources/views/navalha/products.blade.php view and app/Navalha/Products.php class.

To render the component, your need to writen the follow code:

@navalha("Products")

Navalha component example

In follow example, we will paginate the data of Product Eloquent model in server-side component. In the view, the values will be convert to AlpineJs variables.

See:

namespace App\Navalha;

use App\Models\Product;
use WallaceMaxters\Navalha\Component;

class Products extends Component
{
    public function mount(): void
    {
        $this->paginate(1);
    }

    protected function data(): array
    {
        return [
            'page'     => 1,
            'products' => null,
        ];
    }

    public function paginate(int $page)
    {
        $this['products'] = Product::query()->paginate(3, page: $page);
        $this['page'] = $page;

        // or
        // $this->set('page', $page);
    }

    public function render()
    {
        return view("navalha.products");
    }
}

Code of resources/views/navalha/products.blade.php:

<div x-bind:class="{'opacity-0 duration-1000' : !$n.$busy('paginate')}">
    Carregando...
</div>
<div class="space-y-4" >
    <template x-for="item in products.data">
        <div class="bg-neutral-300 p-3 rounded-lg shadow">
            <span x-text="`this is a text ${item.name}`" />
        </div>
    </template>

    <nav class="flex gap-2">
        <template x-for="i in products.last_page">
            <a  x-bind:class="{'opacity-50' : i === products.current_page}"
                x-on:click="$n.paginate(i)"
                x-text="i"
                class="text-blue-500 cursor-pointer p-2"></a>
        </template>
    </nav>
</div>

Code of welcome.blade.php:

<html>
<head>
    @navalhaStyles
    @vite(['resources/css/app.css'])
    @navalhaScripts
</head>
<body>
    <div class="max-w-6xl mx-auto p-8">
        <h1 class="text-3xl font-bold">Navalha Example</h1>
        @navalha('Products')
    </div>
</body>
</html>

Code of route:

Route::view('/', 'welcome');

Navalha special frontend variables and methods

Variable Type Description
$n.$busy(String|undefined) Function Indicates that an specifiy or any method is called from the server.
$n.$errors(String|undefined) Function Get an or many validation errors.
$n.[method]() Function Call a public method of component in Laravel side.
$n Object This a special object from Navalha that allows make methods call like $call().

Handle Server Errors

Your can detect errors on call Navalha method with navalha-errors event.

Example:

<div x-on:navalha-error="console.log($event.detail)">
    <button x-on:click="$navalha.notExistsMethod()">Test</button>
</div>

wallacemaxters/laravel-navalha 适用场景与选型建议

wallacemaxters/laravel-navalha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 wallacemaxters/laravel-navalha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wallacemaxters/laravel-navalha 我们能提供哪些服务?
定制开发 / 二次开发

基于 wallacemaxters/laravel-navalha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-15