diff --git a/app/Concert.php b/app/Concert.php index bf2bd1d..8abac29 100644 --- a/app/Concert.php +++ b/app/Concert.php @@ -8,4 +8,9 @@ class Concert extends Model { protected $guarded = []; protected $dates = ['date']; + + public function getFormattedDateAttribute() + { + return $this->date->format('F j, Y'); + } } diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 7926c79..b46886f 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -1,5 +1,7 @@ define(App\User::class, function (Faker\Generator $faker) { 'remember_token' => str_random(10), ]; }); + +$factory->define(App\Concert::class, function (Faker\Generator $faker) { + return [ + 'title' => 'Example Band', + 'subtitle' => 'with The Fake Openers', + 'date' => Carbon::parse('+2 weeks'), + 'ticket_price' => 2000, + 'venue' => 'The Example Theatre', + 'venue_address' => '123 Example Lane', + 'city' => 'Fakeville', + 'state' => 'ON', + 'zip' => '90210', + 'additional_information' => 'Some sample additional information.', + ]; +}); diff --git a/resources/views/concerts/show.blade.php b/resources/views/concerts/show.blade.php index 9405722..337def9 100644 --- a/resources/views/concerts/show.blade.php +++ b/resources/views/concerts/show.blade.php @@ -1,6 +1,6 @@

{{ $concert->title }}

{{ $concert->subtitle }}

-

{{ $concert->date->format('F j, Y') }}

+

{{ $concert->formatted_date }}

Doors at {{ $concert->date->format('g:ia') }}

{{ number_format($concert->ticket_price / 100, 2) }}

{{ $concert->venue }}

diff --git a/tests/unit/ConcertTest.php b/tests/unit/ConcertTest.php new file mode 100644 index 0000000..17e2182 --- /dev/null +++ b/tests/unit/ConcertTest.php @@ -0,0 +1,27 @@ +create([ + 'date' => Carbon::parse('2016-12-01 8:00pm'), + ]); + + // Retrieve the formatted date + $date = $concert->formatted_date; + + // Verify the date is formatted as expected + $this->assertEquals('December 1, 2016', $date); + } +}