Browse Source

Add name_link attribute on Subscription model

pull/37/head
Nafies Luthfi 7 years ago
parent
commit
9f3166b704
  1. 15
      app/Entities/Subscriptions/Subscription.php
  2. 15
      tests/Unit/Models/SubscriptionTest.php

15
app/Entities/Subscriptions/Subscription.php

@ -35,6 +35,21 @@ class Subscription extends Model
}
/**
* Show subscription name with link to subscription detail attribute.
*
* @return Illuminate\Support\HtmlString
*/
public function getNameLinkAttribute()
{
return link_to_route('subscriptions.show', $this->name, $this, [
'title' => __(
'app.show_detail_title',
['name' => $this->name, 'type' => __('subscription.subscription')]
),
]);
}
/**
* Check weather the subscription is near it's due date.
*
* @return bool

15
tests/Unit/Models/SubscriptionTest.php

@ -31,6 +31,21 @@ class SubscriptionTest extends TestCase
}
/** @test */
public function it_has_name_link_attribute()
{
$subscription = factory(Subscription::class)->create();
$this->assertEquals(
link_to_route('subscriptions.show', $subscription->name, $subscription, [
'title' => trans(
'app.show_detail_title',
['name' => $subscription->name, 'type' => trans('subscription.subscription')]
),
]), $subscription->name_link
);
}
/** @test */
public function it_has_near_of_due_date_method()
{
$next3Months = Carbon::now()->addMonths(3)->format('Y-m-d');

Loading…
Cancel
Save