57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Post;
|
|
use App\Services\ImageService;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\File;
|
|
use Intervention\Image\Constraint;
|
|
use Intervention\Image\Facades\Image;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
|
|
|
class ImageController extends Controller
|
|
{
|
|
/**
|
|
* @param int $post_id
|
|
* @param string|array $options
|
|
* @param string $image
|
|
* @param ImageService $image_service
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function display($post_id, $options = 'o:full', $image, ImageService $image_service)
|
|
{
|
|
$post = Post::find($post_id);
|
|
|
|
if (Auth::user()->getAuthIdentifier() !== (int)$post->user_id) {
|
|
throw new UnauthorizedHttpException('Cette image ne vous appartient pas.');
|
|
}
|
|
|
|
$original = sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), $image);
|
|
if ('o:full' === $options) {
|
|
$img = $image_service->makeThumbnail($original);
|
|
} else {
|
|
$img = $image_service->makeThumbnail($original, ['width' => 300]);
|
|
}
|
|
|
|
return $img->response(File::extension($original));
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function gallery()
|
|
{
|
|
$posts_with_image = Post::where('user_id', Auth::user()->getAuthIdentifier())
|
|
->where('image', '!=', 'null')
|
|
->orderBy('created_at', 'desc')
|
|
->paginate(9);
|
|
|
|
return view('gallery.my', [
|
|
'posts' => $posts_with_image,
|
|
]);
|
|
}
|
|
}
|