Skip to content

Commit

Permalink
Adding an accessor to the Redirect Model
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Mar 4, 2017
1 parent d43f4ae commit 8468424
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/Models/Redirect.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Arcanedev\LaravelSeo\Models;

use Arcanedev\LaravelSeo\Entities\RedirectStatuses;
use Arcanedev\LaravelSeo\Seo;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -13,6 +14,7 @@
* @property string old_url
* @property string new_url
* @property int status
* @property string status_name
* @property \Carbon\Carbon created_at
* @property \Carbon\Carbon updated_at
*/
Expand Down Expand Up @@ -54,6 +56,20 @@ public function __construct(array $attributes = [])
$this->setTable(Seo::getConfig('redirects.table', 'redirects'));
}

/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
*/
/**
* Get the `status_name` attribute.
*
* @return string
*/
public function getStatusNameAttribute()
{
return RedirectStatuses::get($this->status);
}

/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion tests/Models/RedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RedirectTest extends TestCase
/** @test */
public function it_can_create()
{
Redirect::createOne(
$redirect = Redirect::createOne(
$old = '/old-url',
$new = '/new-url'
);
Expand All @@ -29,5 +29,8 @@ public function it_can_create()
'new_url' => $new,
'status' => Response::HTTP_MOVED_PERMANENTLY,
]);

// Assert the accessors
$this->assertSame('[301] Moved Permanently', $redirect->status_name);
}
}

0 comments on commit 8468424

Please sign in to comment.