Skip to content

Instantly share code, notes, and snippets.

@ahuggins
Created February 26, 2017 03:08
Show Gist options
  • Select an option

  • Save ahuggins/bc55d0bdc1e76e8864be73f1603fb14c to your computer and use it in GitHub Desktop.

Select an option

Save ahuggins/bc55d0bdc1e76e8864be73f1603fb14c to your computer and use it in GitHub Desktop.
Post
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public static function findBySlug($slug)
{
return self::where('slug', $slug)->first();
}
public function author()
{
return $this->belongsTo(User::class);
}
public function getImageAttribute($value)
{
return new Image($value);
}
public function getLinkAttribute()
{
return url('blog/' . $this->slug);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment