Initial commit
This commit is contained in:
26
app/Http/Controllers/Api/PhotoController.php
Normal file
26
app/Http/Controllers/Api/PhotoController.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Models\Photo;
|
||||
|
||||
class PhotoController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$photos = Photo::orderBy('sort_order', 'asc')->get();
|
||||
|
||||
$photosWithPaths = $photos->map(function ($photo) {
|
||||
$data = $photo->toArray();
|
||||
$data['photo'] = $photo->photo ? '/storage/' . $photo->photo : null;
|
||||
return $data;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $photosWithPaths
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user