I have a task to make some logic in the Comments Controller in my Level 10.0 project.
In the task, they gave me a text file with bed words on each new line inside the file, named bad_words.txt.
I should implement logic in the Laravel controller before storing a new comment so that every bad word from the file that exists in the input request that is named comment, to be replaced with stars before storing comments in the database.
I am confused about where in the project should I put that file and how to read it and sanitize the comment before storing it in the database if any word from the file is present in the comment input request.
before you save the comment to the database, you can string replace against an array of 'bad words'.
So you have to first read the bad words into an array from the file system. You can use file_get_contents() to read the file to a string then use explode() to create an array, splitting on the new line.
@Snapey Great, thank you for your answer, but what makes me confused still, is where I should put that bad_words.txt file in the root of the Laravel project like .env and etc file or somewhere else. How to load it with file_get_content how to get the path?