oliverbusk
3 months ago

Controller/Route design for "frontend updating"

Posted 3 months ago by oliverbusk

Hi all

So I have a Vue component called "EditorView.vue". This is a frontend editor, where my users can edit images (crop, resize, add effects etc.)

My editor has two steps:

  1. The image is loaded and the user can do some preprocessing (optimize the image, change DPI etc.)
  2. The "preprocessed" image is loaded, and in this step, the user can do the resizing, cropping etc.

Now when going from step 1 to step 2, the image will need to hit the backend, in order for my server to do the actual preprocessing of the image. The processed image is then returned back to the Vue view and served in step 2.

I've just watched the Cruddy By Design by Adam Wathan, where he talks about implementing the CRUD setup for controllers and keep the number of actions within controllers to a minimal.

I am currently stuck on how to solve this, and how to call the backend.

Let's say I have below controller:

Api\Editor\ImagesController.php

and inside this controller, I have the basic CRUD actions.

I have below route defined:

Route::apiResource('editor/image', 'Editor\ImagesController');

I would then need to have methods such as optimizeImage(), changeDPI() in my step 1, and in step 2, I would need methods such as cropImage(), 'resizeImage()`

However, this has nothing to do with CRUD - it's custom actions to manipulate the image, that I have in my controller.

So what is the best approach to solving this? Should I treat the controllers for my editor differently than the rest?

Please sign in or create an account to participate in this conversation.