Stuff
This commit is contained in:
parent
2e6f6836f9
commit
bb21247c31
4 changed files with 60 additions and 0 deletions
|
@ -23,6 +23,23 @@ class PublicController extends BaseController
|
|||
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function listGalleriesViewAPI($name, Request $request) {
|
||||
$data = [];
|
||||
$tenant = Tenant::query()->where("url", "=", $name)->firstOrFail();
|
||||
$galleries = Gallery::query()
|
||||
->where("tenant", "=", $tenant->id)
|
||||
->where("status", "=", "online")
|
||||
->where("listed", "=", 1)
|
||||
->orderByDesc("gallery_create_time")
|
||||
->orderByDesc("created_at")
|
||||
->get();
|
||||
$parser = new \Parsedown();
|
||||
foreach ($galleries as $gallery) {
|
||||
$gallery->html = $parser->parse($gallery->description);
|
||||
}
|
||||
|
||||
return response()->json(["data" => \App\Http\Resources\Gallery::collection(collect($galleries))]);
|
||||
}
|
||||
public function listGalleriesView($name, Request $request) {
|
||||
$tenant = Tenant::query()->where("url", "=", $name)->firstOrFail();
|
||||
$galleries = Gallery::query()
|
||||
|
|
36
app/Http/Resources/Gallery.php
Normal file
36
app/Http/Resources/Gallery.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Gallery extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$data = [];
|
||||
$data["id"] = $this->id;
|
||||
$data["name"] = $this->name;
|
||||
$data["created"] = $this->gallery_create_time;
|
||||
$data["url"] = [
|
||||
"name" => $this->url,
|
||||
"url" => url("/".$this->getTenant()->url."/".$this->url)];
|
||||
$data["mainImage"] = [
|
||||
"id" => $this->main_image,
|
||||
"url" => [
|
||||
"small" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=small"),
|
||||
"medium" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=medium"),
|
||||
"big" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=big")
|
||||
]];
|
||||
$data["description"] = $this->description;
|
||||
$data["tags"] = json_decode($this->tags);
|
||||
return $data;
|
||||
#return parent::toArray($request);
|
||||
}
|
||||
}
|
|
@ -45,4 +45,9 @@ class Gallery extends Authenticatable
|
|||
public static function getByTenantAndUrl($tenant_id, $url) {
|
||||
return Gallery::query()->where("tenant", "=", $tenant_id)->where("url", "=", $url)->first();
|
||||
}
|
||||
|
||||
public function getTenant() {
|
||||
$tenant = Tenant::query()->where("id", "=", $this->tenant)->firstOrFail();
|
||||
return $tenant;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,10 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class, \App\Http\Middle
|
|||
Route::post("a/themes", [\App\Http\Controllers\AdminController::class, "themesSettings"]);
|
||||
});
|
||||
|
||||
Route::get("/{name}.json", [\App\Http\Controllers\PublicController::class, 'listGalleriesViewAPI'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
|
||||
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
|
||||
Route::get("/{tenant}/{gallery}", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
|
||||
Route::get("/{tenant}/{gallery}.json", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
|
||||
Route::get("/{tenant}/{gallery}/{image}/file", [\App\Http\Controllers\PublicController::class, 'returnImageFile']);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue