Implement creator studio and upload updates
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ArtworkIndexRequest;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Category;
|
||||
use App\Models\ContentType;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
@@ -66,7 +67,7 @@ class ArtworkController extends Controller
|
||||
$artworkSlug = $artwork->slug;
|
||||
} elseif ($artwork) {
|
||||
$artworkSlug = (string) $artwork;
|
||||
$foundArtwork = Artwork::where('slug', $artworkSlug)->first();
|
||||
$foundArtwork = $this->findArtworkForCategoryPath($contentTypeSlug, $categoryPath, $artworkSlug);
|
||||
}
|
||||
|
||||
// When the URL can represent a nested category path (e.g. /skins/audio/winamp),
|
||||
@@ -104,4 +105,24 @@ class ArtworkController extends Controller
|
||||
$foundArtwork->slug,
|
||||
);
|
||||
}
|
||||
|
||||
private function findArtworkForCategoryPath(string $contentTypeSlug, string $categoryPath, string $artworkSlug): ?Artwork
|
||||
{
|
||||
$contentType = ContentType::query()->where('slug', strtolower($contentTypeSlug))->first();
|
||||
$segments = array_values(array_filter(explode('/', trim($categoryPath, '/'))));
|
||||
$category = $contentType ? Category::findByPath($contentType->slug, $segments) : null;
|
||||
|
||||
$query = Artwork::query()->where('slug', $artworkSlug);
|
||||
|
||||
if ($category) {
|
||||
$query->whereHas('categories', function ($categoryQuery) use ($category): void {
|
||||
$categoryQuery->where('categories.id', $category->id);
|
||||
});
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderByDesc('published_at')
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user