Skip to content

Commit c401e09

Browse files
committed
init
1 parent 5de4c70 commit c401e09

29 files changed

+350
-637
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Ask a question
4-
url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a
4+
url: https://github.com/Bitcodesa/nova-label/discussions/new?category=q-a
55
about: Ask the community for help
66
- name: Request a feature
7-
url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas
7+
url: https://github.com/Bitcodesa/nova-label/discussions/new?category=ideas
88
about: Share ideas for new features
99
- name: Report a security issue
10-
url: https://github.com/:vendor_name/:package_name/security/policy
10+
url: https://github.com/Bitcodesa/nova-label/security/policy
1111
about: Learn how to notify us for sensitive bugs

.github/dependabot.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/dependabot-auto-merge.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/phpstan.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Changelog
22

3-
All notable changes to `:package_name` will be documented in this file.
3+
All notable changes to `nova-label` will be documented in this file.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) :vendor_name <author@domain.com>
3+
Copyright (c) Bitcodesa <m.abather@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 103 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,135 @@
1-
# :package_description
1+
# Create Labels for Nova Resources with different languages.
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
7-
<!--delete-->
8-
---
9-
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/abather/nova-label.svg?style=flat-square)](https://packagist.org/packages/abather/nova-label)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/abather/nova-label.svg?style=flat-square)](https://packagist.org/packages/abather/nova-label)
5+
## Improved Documentation:
106

11-
1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
12-
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
13-
3. Have fun creating your package.
14-
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
15-
---
16-
<!--/delete-->
17-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
7+
**Dynamically Manage Labels for Nova Resources**
188

19-
## Support us
9+
This document details how to dynamically manage labels for Nova resources using the `abather/nova-label` package.
2010

21-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
11+
## Installation
2212

23-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
13+
Install the package using Composer:
2414

25-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
15+
```bash
16+
composer require abather/nova-label
17+
```
2618

27-
## Installation
19+
## Usage
2820

29-
You can install the package via composer:
21+
1. **Include ResourceLabel**:
3022

31-
```bash
32-
composer require :vendor_slug/:package_slug
23+
In `App/Nova/Resource.php`, extend the `NovaResource` class and add the `ResourceLabel` trait:
24+
25+
```php
26+
<?php
27+
28+
namespace App\Nova;
29+
30+
use Bitcodesa\NovaLabel\ResourceLabel;
31+
use Laravel\Nova\Http\Requests\NovaRequest;
32+
use Laravel\Nova\Resource as NovaResource;
33+
34+
abstract class Resource extends NovaResource
35+
{
36+
use ResourceLabel;
37+
38+
// ...
39+
}
3340
```
3441

35-
You can publish and run the migrations with:
42+
2. **Generate Labels**:
3643

37-
```bash
38-
php artisan vendor:publish --tag=":package_slug-migrations"
39-
php artisan migrate
44+
Use the `self::attribute()` method to generate field labels. This method handles both field name and database attribute:
45+
46+
```php
47+
Text::make(...self::attribute('name')); // field name and attribute same
4048
```
4149

42-
You can publish the config file with:
50+
**Optional Parameters:**
4351

44-
```bash
45-
php artisan vendor:publish --tag=":package_slug-config"
52+
* **Attribute name:**
53+
54+
Specify a different database attribute name:
55+
56+
```php
57+
Text::make(...self::attribute('name', 'fullName')); // field name: name, attribute: fullName
4658
```
4759

48-
This is the contents of the published config file:
60+
* **Title only:**
61+
62+
Return only the attribute title:
4963

5064
```php
65+
Text::make(self::attribute('name', title_only: true));
66+
```
67+
68+
3. **Handle Relationships:**
69+
70+
For relationship fields, pass the corresponding resource class as the first parameter to `self::relation()`:
71+
72+
```php
73+
BelongsTo::make(...self::relation(\App\Nova\User::class, many: false)); // One-to-one relationship
74+
```
75+
76+
**Relationship Label Customization:**
77+
78+
Similar to field labels, you can customize relationship labels with `title` and `relation` parameters:
79+
80+
```php
81+
HasMany::make(...self::relation(\App\Nova\Task::class, title: "Tasks", relation: "tasks"));
82+
```
83+
84+
## Localization
85+
86+
### File Structure
87+
88+
Each resource has a dedicated localization file for field and other translations. The file structure should follow:
89+
90+
```php
91+
<?php
92+
5193
return [
94+
// Resource name in singular and plural form
95+
"resource" => "Resource",
96+
"resources" => "Resources",
97+
98+
// Button labels
99+
"buttons" => [
100+
"create" => "Create Resource",
101+
"update" => "Update Resource",
102+
],
103+
104+
// Attributes
105+
"attributes" => [
106+
// Translate each attribute name
107+
"created_at" => __("created_at"),
108+
// ...
109+
],
110+
111+
// Additional sections (optional)
52112
];
53113
```
54114

55-
Optionally, you can publish the views using
115+
### Create Localization Files
116+
117+
To create a new localization file for a specific resource and language:
56118

57119
```bash
58-
php artisan vendor:publish --tag=":package_slug-views"
120+
php artisan make:label ResourceName LanguageSample
59121
```
60122

61-
## Usage
123+
For example, to create an Arabic translation file for the `Book` resource:
62124

63-
```php
64-
$variable = new VendorName\Skeleton();
65-
echo $variable->echoPhrase('Hello, VendorName!');
125+
```bash
126+
php artisan make:label Book ar
66127
```
67128

129+
This command generates a file at `Lang/ar/Book.php`. Translate each line in the file according to your needs.
130+
131+
**Note:** Run `php artisan migrate` before creating the localization file to ensure all column names are available for translation.
132+
68133
## Testing
69134

70135
```bash
@@ -85,7 +150,7 @@ Please review [our security policy](../../security/policy) on how to report secu
85150

86151
## Credits
87152

88-
- [:author_name](https://github.com/:author_username)
153+
- [Abather M.S](https://github.com/abather)
89154
- [All Contributors](../../contributors)
90155

91156
## License

composer.json

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
{
2-
"name": ":vendor_slug/:package_slug",
3-
"description": ":package_description",
2+
"name": "bitcodesa/nova-label",
3+
"description": "Create Labels for Nova Resources with different languages.",
44
"keywords": [
5-
":vendor_name",
5+
"Bitcodesa",
66
"laravel",
7-
":package_slug"
7+
"nova-label",
8+
"nova"
89
],
9-
"homepage": "https://github.com/:vendor_slug/:package_slug",
10+
"version": "1.0.0",
11+
"homepage": "https://github.com/abather/nova-label",
1012
"license": "MIT",
1113
"authors": [
1214
{
13-
"name": ":author_name",
14-
"email": "author@domain.com",
15+
"name": "Abather M.S",
16+
"email": "m.abather@gmail.com",
1517
"role": "Developer"
1618
}
1719
],
1820
"require": {
1921
"php": "^8.1",
22+
"laravel/framework": "^10.0",
2023
"spatie/laravel-package-tools": "^1.14.0",
2124
"illuminate/contracts": "^10.0"
2225
},
@@ -27,27 +30,23 @@
2730
"orchestra/testbench": "^8.8",
2831
"pestphp/pest": "^2.20",
2932
"pestphp/pest-plugin-arch": "^2.0",
30-
"pestphp/pest-plugin-laravel": "^2.0",
31-
"phpstan/extension-installer": "^1.1",
32-
"phpstan/phpstan-deprecation-rules": "^1.0",
33-
"phpstan/phpstan-phpunit": "^1.0",
34-
"spatie/laravel-ray": "^1.26"
33+
"pestphp/pest-plugin-laravel": "^2.0"
3534
},
3635
"autoload": {
3736
"psr-4": {
38-
"VendorName\\Skeleton\\": "src/",
39-
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
37+
"Bitcodesa\\NovaLabel\\": "src/",
38+
"Bitcodesa\\NovaLabel\\Database\\Factories\\": "database/factories/"
4039
}
4140
},
4241
"autoload-dev": {
4342
"psr-4": {
44-
"VendorName\\Skeleton\\Tests\\": "tests/",
43+
"Bitcodesa\\NovaLabel\\Tests\\": "tests/",
4544
"Workbench\\App\\": "workbench/app/"
4645
}
4746
},
4847
"scripts": {
4948
"post-autoload-dump": "@composer run prepare",
50-
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
49+
"clear": "@php vendor/bin/testbench package:purge-nova-label --ansi",
5150
"prepare": "@php vendor/bin/testbench package:discover --ansi",
5251
"build": [
5352
"@composer run prepare",
@@ -73,10 +72,10 @@
7372
"extra": {
7473
"laravel": {
7574
"providers": [
76-
"VendorName\\Skeleton\\SkeletonServiceProvider"
75+
"Bitcodesa\\NovaLabel\\NovaLabelServiceProvider"
7776
],
7877
"aliases": {
79-
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
78+
"NovaLabel": "Bitcodesa\\NovaLabel\\Facades\\NovaLabel"
8079
}
8180
}
8281
},

config/nova-label.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
// config for Bitcodesa/NovaLabel
4+
return [
5+
6+
];

0 commit comments

Comments
 (0)