Skip to content

Commit

Permalink
Add method modelLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
madnh committed Mar 1, 2017
1 parent 796e38e commit 3e404e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Use following methods to get labels

| **Method** | **Example** | **Description** |
|---------------------------|------------------------------------------------------|-----------------------------|
| **modelLabel()** | `Country::modelLabel()` | Get label of model class |
| **labels()** | `Country::labels()` | Get all of lables of fields |
| **labels(<fields name>)** | `Country::labels('name', 'flag', 'code', ['title'])` | Get label of fields |
| **label(<field name>)** | `Country::label('name')` | Get label of a field |
Expand Down
13 changes: 13 additions & 0 deletions src/LabelsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,17 @@ protected static function getLabelI18nPath($sub_path = null)

return $path;
}

public static function getModelLabel()
{
$class_basename = class_basename(static::class);
$trans = 'model_' . strtolower($class_basename) . '.model';
$label = trans($trans);

if (is_string($label) && $trans !== $label) {
return $label;
}

return title_case($class_basename);
}
}

0 comments on commit 3e404e5

Please sign in to comment.