Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Category | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| getParentKeyName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLocalKeyName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPath | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 6 | use Illuminate\Database\Eloquent\Model; |
| 7 | use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract; |
| 8 | use Astrotomic\Translatable\Translatable; |
| 9 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 10 | use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
| 11 | use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships; |
| 12 | class Category extends Model implements TranslatableContract |
| 13 | { |
| 14 | use HasFactory, Translatable, SoftDeletes; |
| 15 | use HasRecursiveRelationships; |
| 16 | protected $table = 'categories'; |
| 17 | public $translatedAttributes = ['name']; |
| 18 | protected $guarded = []; |
| 19 | |
| 20 | public function getParentKeyName() |
| 21 | { |
| 22 | return 'parent_id'; |
| 23 | } |
| 24 | |
| 25 | public function getLocalKeyName() |
| 26 | { |
| 27 | return 'id'; |
| 28 | } |
| 29 | |
| 30 | public function getPath(){ |
| 31 | $cats = $this->ancestors()->orderBy('depth', 'ASC')->get(); |
| 32 | $path = ''; |
| 33 | foreach($cats as $cat){ |
| 34 | $path .= '/' . $cat->translate(LaravelLocalization::getCurrentLocale())->name; |
| 35 | } |
| 36 | |
| 37 | return $path; |
| 38 | } |
| 39 | } |