Call a function on every text field in laravel eloquent

  database-migration, eloquent, laravel, php

Problem Background: In my DB we are migrating data from MSSQL to MySQL, now while migrating we ned to escape various strings as there are many html contents and other contents which need to be escaped.

Real Problem: Now all the text strings have / (slash added) to them I want to remove these after fetching data in eloquent model preferably from a single function or event so that I not need to call slash removing functions on each string field. I can’t call stripslashes on fields cause I am not sure on which field the slashes added or not cause its possible in same column value once or twice the slash might be added or may be not. So a generic solution is required.

Can anyone help me with this ?
as I am not sure How I’ll be able to do this:

I guess "Eloquent Mutators" can be used but again they need to be defined explicitly for each field, where as I would like to have a generic method which can be called on each and every text field.

Source: Laravel

Leave a Reply