title: best way to run string functions over returned database object
body: <p>I need to run various string functions over the data returned from the database before I send it to the view using Laravel 5.3.  Basic stuff like str_replace().</p>
  
  <p>Now maybe there's a good way to setup Accessors on my model and somehow use the model on the landing page but I thought I would go a different route and just do this one query manually outside of the model.</p>
  
  <p>So I have a view provider that successfully gets my data into the view.  It looks like this:</p>
  
  <pre><code>class ViewLandingProvider extends ServiceProvider {
     public function boot() {
      // process when featured homepage element is present...
      View::composer('mybladetemplate', function ($view){
  
          $featuredProperties = DB::table('properties')
              -&gt;where([
                  ['featured_property', '=', '1'],
                  ['supplier_id', '=', 123],
              ])
              -&gt;orderBy('prop_id', 'desc')
              -&gt;limit(6)
              -&gt;get();
  
          // run str_replace!
          $featuredProperties-&gt;each(function($property){
              $property-&gt;prop_url=str_replace("http://domain.com/","http://www.domain.com/",$property-&gt;prop_url);
          });
  
          View::share('featuredProperties', $featuredProperties);
      });
    }
  }
  </code></pre>
  
  <p>this then loops within a view and it all works nicely</p>
  
  <pre><code> @if(isset($featuredProperties))
       @foreach ($featuredProperties as $property)
           &lt;li&gt;
               &lt;a title="{{ $property-&gt;prop_name }}" href="{{ $property-&gt;prop_url }}"&gt;&lt;/a&gt;
           &lt;/li&gt;           
      @endforeach
  @endif
  </code></pre>
  
  <p>As you can see in the example above, I have str_replace() running over the data collection using ->each() and that's working to let me do a simple string replacement that I need to undertake.  </p>
  
  <p>Being Laravel though, I'm sure there's some magic that could be pulled here to do this more intelligently.  </p>
  
  <p>So is there a way in the actual database request code that I can specify that a certain column to be returned should automatically have a function run over it ?</p>
  
  <p>Just to clarify, I want to make these changes in the provider php rather than the view file and I want to do this outside of a model with Accessors.</p>