1.7 - Testing Query Scopes

This commit is contained in:
Adam Wathan
2016-11-03 15:05:59 -04:00
parent 1a5f7c7e89
commit 12e18f3728
4 changed files with 24 additions and 2 deletions

View File

@@ -9,6 +9,11 @@ class Concert extends Model
protected $guarded = [];
protected $dates = ['date'];
public function scopePublished($query)
{
return $query->whereNotNull('published_at');
}
public function getFormattedDateAttribute()
{
return $this->date->format('F j, Y');

View File

@@ -9,7 +9,7 @@ class ConcertsController extends Controller
{
public function show($id)
{
$concert = Concert::whereNotNull('published_at')->findOrFail($id);
$concert = Concert::published()->findOrFail($id);
return view('concerts.show', ['concert' => $concert]);
}
}