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+
5193return [
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
0 commit comments