diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/DashboardController.php similarity index 92% rename from app/Http/Controllers/HomeController.php rename to app/Http/Controllers/DashboardController.php index 65bde6d..b92e488 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/DashboardController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Post; use App\PostsTag; +use App\Services\ImageService; use App\Services\TagDetectorService; use App\Tag; use DateTime; @@ -13,7 +14,7 @@ use Illuminate\Support\Facades\Redirect; use Intervention\Image\Constraint; use Intervention\Image\Facades\Image; -class HomeController extends Controller +class DashboardController extends Controller { /** * Create a new controller instance. @@ -127,7 +128,7 @@ class HomeController extends Controller * @return mixed * @throws \Exception */ - public function store(TagDetectorService $tag_detector) + public function store(TagDetectorService $tag_detector, ImageService $image_service) { $user_id = Auth::user()->getAuthIdentifier(); @@ -147,10 +148,7 @@ class HomeController extends Controller $uploaded_document = $validated_data['file']; $file_name = $uploaded_document->getClientOriginalName(); $uploaded_document->storeAs(Auth::user()->getFolder(), $file_name); - $img = Image::make($uploaded_document->getRealPath()); - $img->resize(300, null, static function (Constraint $constraint) { - $constraint->aspectRatio(); - })->save(sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), sprintf('300-%s', $file_name))); + $image_service->makeThumbnail($uploaded_document->getRealPath(), ['width' => 300]); $data['image'] = $file_name; } diff --git a/routes/web.php b/routes/web.php index 475d5e2..17626f2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -14,10 +14,10 @@ Auth::routes(); Route::get('/', 'WelcomeController@index')->name('home'); -Route::get('/home', 'HomeController@index')->name('dashboard'); -Route::post('store', 'HomeController@store')->name('store'); -Route::post('delete', 'HomeController@delete')->name('delete'); -Route::post('edit', 'HomeController@edit')->name('edit'); +Route::get('/home', 'DashboardController@index')->name('dashboard'); +Route::post('store', 'DashboardController@store')->name('store'); +Route::post('delete', 'DashboardController@delete')->name('delete'); +Route::post('edit', 'DashboardController@edit')->name('edit'); Route::post('stats', 'StatsController@tag')->name('stats'); // TODO make a group for stats Route::get('/display/{post_id}/{options}/{image_name}', 'ImageController@display')->name('display_image'); Route::get('/gallery', 'ImageController@gallery')->name('gallery');