@@ -95,7 +95,7 @@ protected function url(): Attribute
95
95
return Attribute::get (fn () => $ this ->getUrl ());
96
96
}
97
97
98
- public function getConversionKey (string $ conversion ): string
98
+ public function makeGeneratedConversionKey (string $ conversion ): string
99
99
{
100
100
return str_replace ('. ' , '.generated_conversions. ' , $ conversion );
101
101
}
@@ -106,7 +106,10 @@ public function getConversionKey(string $conversion): string
106
106
*/
107
107
public function getGeneratedConversion (string $ conversion , ?string $ state = null ): ?GeneratedConversion
108
108
{
109
- $ generatedConversion = data_get ($ this ->generated_conversions , $ this ->getConversionKey ($ conversion ));
109
+ $ generatedConversion = data_get (
110
+ $ this ->generated_conversions ,
111
+ $ this ->makeGeneratedConversionKey ($ conversion )
112
+ );
110
113
111
114
if ($ state ) {
112
115
return $ generatedConversion ?->state === $ state ? $ generatedConversion : null ;
@@ -115,14 +118,6 @@ public function getGeneratedConversion(string $conversion, ?string $state = null
115
118
return $ generatedConversion ;
116
119
}
117
120
118
- public function getGeneratedParentConversion (string $ conversion , ?string $ state = null ): ?GeneratedConversion
119
- {
120
- $ genealogy = explode ('. ' , $ conversion );
121
- $ parents = implode ('. ' , array_slice ($ genealogy , 0 , -1 ));
122
-
123
- return $ this ->getGeneratedConversion ($ parents , $ state );
124
- }
125
-
126
121
public function hasGeneratedConversion (string $ conversion , ?string $ state = null ): bool
127
122
{
128
123
return (bool ) $ this ->getGeneratedConversion ($ conversion , $ state );
@@ -136,8 +131,10 @@ public function hasGeneratedConversion(string $conversion, ?string $state = null
136
131
* /conversionName
137
132
* files
138
133
*/
139
- public function generateBasePath (?string $ conversion = null ): string
140
- {
134
+ public function makePath (
135
+ ?string $ conversion = null ,
136
+ ?string $ fileName = null
137
+ ): string {
141
138
$ prefix = config ('media.generated_path_prefix ' , '' );
142
139
143
140
$ root = Str::of ($ prefix )
@@ -148,11 +145,12 @@ public function generateBasePath(?string $conversion = null): string
148
145
if ($ conversion ) {
149
146
return $ root
150
147
->append ('generated_conversions/ ' )
151
- ->append (str_replace ('. ' , '/ ' , $ this ->getConversionKey ($ conversion )))
152
- ->finish ('/ ' );
148
+ ->append (str_replace ('. ' , '/ ' , $ this ->makeGeneratedConversionKey ($ conversion )))
149
+ ->finish ('/ ' )
150
+ ->append ($ fileName ?? '' );
153
151
}
154
152
155
- return $ root ;
153
+ return $ root-> append ( $ fileName ?? '' ) ;
156
154
}
157
155
158
156
public function putGeneratedConversion (string $ conversion , GeneratedConversion $ generatedConversion ): static
@@ -231,7 +229,7 @@ public function storeFileFromHttpFile(
231
229
232
230
$ file = $ this ->performMediaTransformations ($ file );
233
231
234
- $ basePath = Str::finish ($ basePath ?? $ this ->generateBasePath (), '/ ' );
232
+ $ basePath = Str::finish ($ basePath ?? $ this ->makePath (), '/ ' );
235
233
236
234
$ this ->name = Str::limit (
237
235
File::sanitizeFilename ($ name ?? File::name ($ file )),
@@ -405,7 +403,7 @@ public function storeConversionFromHttpFile(
405
403
name: $ name ,
406
404
extension: $ extension ,
407
405
file_name: $ file_name ,
408
- path: Str::of ($ basePath ?? $ this ->generateBasePath ($ conversion ))->finish ('/ ' )->append ($ file_name ),
406
+ path: Str::of ($ basePath ?? $ this ->makePath ($ conversion ))->finish ('/ ' )->append ($ file_name ),
409
407
mime_type: $ mime_type ,
410
408
type: $ type ,
411
409
state: $ state ,
@@ -610,9 +608,10 @@ public function deleteGeneratedConversion(string $conversion): ?GeneratedConvers
610
608
return null ;
611
609
}
612
610
613
- $ this ->deleteGeneratedConversionFiles ($ conversion );
614
- $ this ->forgetGeneratedConversion ($ conversion );
615
- $ this ->save ();
611
+ $ this
612
+ ->deleteGeneratedConversionFiles ($ conversion )
613
+ ->forgetGeneratedConversion ($ conversion )
614
+ ->save ();
616
615
617
616
return $ generatedConversion ;
618
617
}
0 commit comments