Mixes and editing

A user can only see mixes that have either ID ‘null’ (public mixes) or their own id. When a mix has their own id, a mix will get the ‘editable’ property, and the link to edit will appear. This is also checked in the update controller. if you try to edit a mix that isn’t yours it shouldn’t work. If you try to view a mix that isn’t yours, you’ll be sent back to the index page (see mixes controller).

Admin rights (very simple version):

When a user has is_admin in the user table set to true, they can edit public mixes, with a simple check in the mixes controller update function for this value and in the mixes model, the editable property will be set to true. More complicated roles/permissions are possible with additional tables/migrations and middleware, refer to this note.

Duplicating public mixes

refer to duplicate function in mixes controller, basically creates a new mix template without a user id, with temporary ingredient copies that will not be added to the ingredients table until a user saves the mix.

Doubling/halving in mix interface

With the math.js file, it converts everything to ml, and it converts it back to pinches ts, tbs, or cups depending on what’s logical with certain cut-off values (e.g. you don’t want a recipe with 25 teaspoons of something, so this becomes x amount of cups).

image.png

Sharing: On a share, a new share entry is created with the entire mix as a json object. The email-address that a user types to share, is compared to the email-addresses in the users database. if there’s a match, it will extract the id as target_user. When this target_user logs in, they will get a notification that there’s a share. if they accept it, the mix object. When a user shares a mix from a custom cuisine, this cuisine will also be added for the target user if they accept this.

Adding images:

images are sent together with the rest of the mix to the back-end, but in the mixescontroller (explained in laravel part), they are separated and handled by spatie media library. This also has a separate table and will save the images to the public storage folder.

image.png

Removing mixes: when a user removes a mix, the associated image is also removed, as are the ingredients

Security: Without going into too much detail, I’ve put several limits on all kinds of uploads: maximum image uploads total, maximum image uploads per day, image sizes, maximum number of mixes, maximum characters for strings, maximum number of custom cuisines etc, maximum number of accounts created in a single day etc.

Some more info on database structure of this particular project;