Files
snipe-it/app/models/Model.php
T
2013-11-13 05:56:05 -05:00

74 lines
1.1 KiB
PHP

<?php
class Model extends Eloquent {
/**
* Deletes a blog post and all the associated comments.
*
* @return bool
*/
public function delete()
{
// Delete the comments
$this->comments()->delete();
// Delete the blog post
return parent::delete();
}
/**
* Returns a formatted post content entry, this ensures that
* line breaks are returned.
*
* @return string
*/
public function content()
{
return nl2br($this->content);
}
/**
* Return the post's author.
*
* @return User
*/
public function author()
{
return $this->belongsTo('User', 'user_id');
}
/**
* Return how many comments this post has.
*
* @return array
*/
public function comments()
{
return $this->hasMany('Comment');
}
/**
* Return the URL to the post.
*
* @return string
*/
public function url()
{
return URL::route('view-post', $this->slug);
}
/**
* Return the post thumbnail image url.
*
* @return string
*/
public function thumbnail()
{
# you should save the image url on the database
# and return that url here.
return 'http://lorempixel.com/130/90/business/';
}
}