| 2 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace App\Models;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
6 |
use Illuminate\Database\Eloquent\Model;
|
|
|
7 |
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
8 |
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
9 |
use Illuminate\Support\Collection;
|
|
|
10 |
use Spatie\Sluggable\HasSlug;
|
|
|
11 |
use Spatie\Sluggable\SlugOptions;
|
|
|
12 |
|
| 415 |
lars |
13 |
/**
|
| 486 |
lars |
14 |
* App\Models\Directory
|
|
|
15 |
*
|
|
|
16 |
* @property int $id
|
|
|
17 |
* @property int|null $directory_id
|
|
|
18 |
* @property string $name
|
|
|
19 |
* @property string $slug
|
|
|
20 |
* @property string $kennung
|
|
|
21 |
* @property int $articlemaster
|
|
|
22 |
* @property int $status
|
|
|
23 |
* @property string $url
|
|
|
24 |
* @property string $description
|
|
|
25 |
* @property string $short_line_1
|
|
|
26 |
* @property string $created_by
|
|
|
27 |
* @property string $updated_by
|
|
|
28 |
* @property \Illuminate\Support\Carbon|null $created_at
|
|
|
29 |
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
|
30 |
* @property-read Directory|null $directory
|
|
|
31 |
* @property-read \App\Models\Manufacturer|null $manufacturer
|
|
|
32 |
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DirectoryMedium> $medium
|
|
|
33 |
* @property-read int|null $medium_count
|
|
|
34 |
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DirectoryTemplate> $template
|
|
|
35 |
* @property-read int|null $template_count
|
|
|
36 |
* @method static \Database\Factories\DirectoryFactory factory( $count = null, $state = [] )
|
|
|
37 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory newModelQuery()
|
|
|
38 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory newQuery()
|
|
|
39 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory query()
|
|
|
40 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereArticlemaster( $value )
|
|
|
41 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereCreatedAt( $value )
|
|
|
42 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereCreatedBy( $value )
|
|
|
43 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereDescription( $value )
|
|
|
44 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereDirectoryId( $value )
|
|
|
45 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereId( $value )
|
|
|
46 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereKennung( $value )
|
|
|
47 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereName( $value )
|
|
|
48 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereShortLine1( $value )
|
|
|
49 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereSlug( $value )
|
|
|
50 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereStatus( $value )
|
|
|
51 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereUpdatedAt( $value )
|
|
|
52 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereUpdatedBy( $value )
|
|
|
53 |
* @method static \Illuminate\Database\Eloquent\Builder|Directory whereUrl( $value )
|
|
|
54 |
* @mixin \Eloquent
|
|
|
55 |
*/
|
|
|
56 |
class Directory extends Model
|
| 2 |
lars |
57 |
{
|
|
|
58 |
use HasFactory, HasSlug;
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Get the options for generating the slug.
|
|
|
62 |
*/
|
|
|
63 |
public function getSlugOptions(): SlugOptions
|
|
|
64 |
{
|
|
|
65 |
return SlugOptions::create()
|
|
|
66 |
->generateSlugsFrom( 'name' )
|
|
|
67 |
->saveSlugsTo( 'slug' )
|
|
|
68 |
->usingLanguage( 'de' )
|
|
|
69 |
->doNotGenerateSlugsOnUpdate()
|
|
|
70 |
->skipGenerateWhen( fn() => $this->id < 0 );
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public function directory(): BelongsTo
|
|
|
74 |
{
|
|
|
75 |
return $this->belongsTo( Directory::class );
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
function medium(): HasMany
|
|
|
79 |
{
|
|
|
80 |
return $this->hasMany( DirectoryMedium::class )->orderBy( "rank" );
|
|
|
81 |
}
|
|
|
82 |
|
| 488 |
lars |
83 |
public function sub_dirs(): HasMany
|
|
|
84 |
{
|
|
|
85 |
return $this->hasMany( Directory::class );
|
|
|
86 |
}
|
|
|
87 |
|
| 485 |
lars |
88 |
function items(): HasMany
|
|
|
89 |
{
|
| 488 |
lars |
90 |
return $this->hasMany( Item::class )->with( 'medium.medium', 'price', 'manufacturer' )->orderBy( "id", "DESC" );
|
| 485 |
lars |
91 |
}
|
|
|
92 |
|
| 2 |
lars |
93 |
function template(): HasMany
|
|
|
94 |
{
|
|
|
95 |
return $this->hasMany( DirectoryTemplate::class );
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public function manufacturer(): BelongsTo
|
|
|
99 |
{
|
|
|
100 |
return $this->belongsTo( Manufacturer::class );
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
public function shopPosition(): Collection
|
|
|
104 |
{
|
|
|
105 |
$pos = collect(); //$pos = "Sie sind hier: <a href=\"/\">Startseite</a> <span class='breadcrumb-trenner'> » </span>";
|
|
|
106 |
$path = getPath( $_SESSION['navigation']['position'] )->reverse();
|
|
|
107 |
foreach ( $path as $dir )
|
|
|
108 |
{
|
|
|
109 |
$pos[] = $dir;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
return $pos;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
}
|