offer fileupload and comments
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 10/01/2018
|
||||
* Time: 14:22
|
||||
*/
|
||||
|
||||
class Comment extends BaseModel {
|
||||
|
||||
protected $table = "comments";
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo( 'User' );
|
||||
}
|
||||
|
||||
public static function getComments( $foreignID, $tablename )
|
||||
{
|
||||
$comments = Comment::orderBy( 'comment_date', 'desc' )
|
||||
->with( [
|
||||
'user' => function ( $q ) {
|
||||
$q->selectRaw( "CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname, id" );
|
||||
}] )
|
||||
->whereForeignId( $foreignID )
|
||||
->whereForeignTable( $tablename )
|
||||
->get();
|
||||
|
||||
foreach ( $comments as $comment )
|
||||
{
|
||||
$comment->comment = base64_decode( $comment->comment );
|
||||
}
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
public static function addComment( $foreignID, $tablename )
|
||||
{
|
||||
$data = [
|
||||
'foreign_id' => $foreignID,
|
||||
'foreign_table' => $tablename,
|
||||
'user_id' => USERID,
|
||||
'comment_date' => date( 'Y-m-d H:i:s' )
|
||||
];
|
||||
|
||||
$comment = Comment::create( $data );
|
||||
|
||||
return $comment['id'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user