Set the default __toString() format per Carbon instance?
<p>I retrieve dates from a database and have the option to pre-process them (via the Laravel framework (v5.2)). The dates or times can come in any particular format but for this example let's say <code>Y-m-d</code>.</p>

<p>I want to be able to access the date as a Carbon instance in the view &mdash; this would give me the flexibility to format the date however I please or do nothing with it and print as-is (with the default toString being the same as its original string format).</p>

<p>The issue is maintaining the default expected toString format at the top-level Carbon toString format.</p>

<p>According to the <a href="http://carbon.nesbot.com/docs/#api-formatting" rel="nofollow">docs</a>, you can use the <code>::setToStringFormat()</code> method to change the default format of toString. It is possible to set it with the static method <code>Carbon::setToStringFormat()</code> but it also works as an instance method e.g. <code>($date = Carbon::now())-&gt;setToStringFormat('Y-m-d')</code> - albeit this seems to behave identically to the static method.</p>

<p>So, is it possible to set the individual <code>__toString()</code> format for a date instance?</p>

<p>It would allow me to do the following:</p>

<pre><code>public function getDateAttribute($value)
{
    $date = Carbon::createFromFormat('Y-m-d', $value);
    // $date-&gt;setToStringFormat('Y-m-d');
    return $date; // prints in 'Y-m-d' format
}
</code></pre>

<p>In a view, I would then chain methods on the date, or print it as-is.</p>