I am new in laravel, I run a query and get rows from database and I want to edit a column of this rows before get them in view. So here is my code piece :
$callPlans = CustomerCallPlan::whereNotNull('id');
foreach ($callPlans->get() as $callPlan) {
dd($callPlan);
}
And the output screenshot:
I need to replace all the 'x' characters with '-' of numbertemplate
column..
You could do the following:
Hope this was helpful.
If you want to do this transformations always for your model, you can just add the following accessor method to the model class:
Now everytime you access $customerCallPlan->numbertemplate you will get the converted string.
Otherwise just convert the column when you fetch the data:
You could use
update()
andstr_replace()
:Hope this helps.