mercredi 9 octobre 2019

How to implement region-specific app in Laravel Controllers

I am using Laravel 6.

I am building an app that has Files (not a file stored on your desktop or storage). I have a File model, FileController controller and Files in the DB with id, user_id (as it belongs to a user) and data (which is a JSON column).

For my app, a File can have different fields, based on jurisdiction, that need to be captured (via forms on the blade templates) and managed via the controller (primarily via show, edit, update).

It is likely that I have many jurisdictions (imagine country, state and maybe city) versions of Files, with their respective fields that need to be captured, displayed, modified, etc.

In many of these Files, especially if its in the same country, there are fields (columns/keys) that are repeated.

Currently, I have one Controller, and when it comes to editing a File, showing a File or updating a File, I am starting to have logic that detects the country or state and modifying the logic or view.

Initially I thought I would do something like this

File - model
FileController - root controller
- @edit will call FileControllers/country/state/FileController@edit.php
- @show will call FileControllers/country/state/FileController@show.php
- @update will reference FileControllers/country/state/FileController@update
Files.view.blade - root view for Show
Files.edit.blade - root view for Edit

but I have a feeling this is going to get out of hand really quickly, especially if certain File records have similar fields, views, data types that I will capture. There aren't any that are consist across the various different jurisdictions, which is why I opted for a JSON store in the mysql database.

What are some ways to dynamically manage this sort of setup with relative ease of maintainability, in the long run? I am a beginner-ish to novice-ish developer.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire