Skip to content

Instantly share code, notes, and snippets.

@lifesign
Created October 16, 2014 11:49
Show Gist options
  • Save lifesign/74f52cfdff1de48e60c8 to your computer and use it in GitHub Desktop.
Save lifesign/74f52cfdff1de48e60c8 to your computer and use it in GitHub Desktop.
laravel use collection each
<?php
class PagesController extends BaseController
{
public function index()
{
$featuredEvents = Event::where('featured', '1')->get();
$featuredEvents->each(function ($event) {
$event->dateFormatted = Carbon::createFromFormat('d/m/Y', $event->date)->formatLocalized('%A %d %B');
});
return View::make('index')->with('featuredEvents', $featuredEvents);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment