TutanRamon's avatar

Store rich content

I am building a Laravel application which allows users to post news articles on their website.

A news article (post) may contain html and may include images. Now, the images, that's the tricky part.

I could just allow an user to insert an image (store the image on disk) and insert the -part directly in the post. For example:

<p>This is a post and this post contains an image: <img src="foobar.jpg" width="400" height="500" alt="dummy"></p>'

The downside of this approach is that I don't have a clue which images are used in which posts. Another, possible downside, is that I need to generate AMP-pages as well (which have their own -tags with mandatory attributes 'height' and 'width').

I was thinking to do the following:

  • User can upload image. The script then adds a custom tag to the post, ie ". As you can see, a new image model instance is created and 'attached' to the post model using relations.

Then, upon loading the frontend, I can replace the customIMG tag with the corresponding HTML or AMP-HTML.

Is this a wise idea or does somebody have a better idea?

0 likes
1 reply
Snapey's avatar

unfortunately your proposed code does not show in the post.

I guess you are talking about some form of custom tag eg like [image:456357] and then search and replace when outputting the block.

The only downside would be if the user for some reason needed to write [image: in their post

Please or to participate in this conversation.