コード例 #1
0
 /**
  * Returns collection of all image attachments
  * @return mixed
  */
 public function getAllImageAttachments($context = null)
 {
     $model = get_class();
     if ($context) {
         return Attachment::where('model_id', $this->id)->where('context', $context)->where('model', $model)->orderBy('priority', 'asc')->get();
     }
     //if no context, return all attachments
     return Attachment::where('model_id', $this->id)->where('model', $model)->orderBy('priority', 'asc')->get();
 }
コード例 #2
0
ファイル: Attachment.php プロジェクト: larapress/larapress
 /**
  * Returns an array of objects in a format suitable for vue to populate attachments
  */
 public static function getByModel($model, $model_id, $context)
 {
     $attachments = Attachment::where('model_id', $model_id)->where('context', $context)->where('model', $model)->orderBy('priority', 'asc')->get();
     $result = [];
     foreach ($attachments as $attachment) {
         $details = new \stdClass();
         $details->id = $attachment->id;
         $details->url = $attachment->url;
         $details->alt = $attachment->alt;
         $details->caption = $attachment->caption;
         $details->priority = $attachment->priority;
         $result[] = $details;
     }
     return $result;
 }
コード例 #3
0
 /**
  * Return the json to populate the attachment list for a context
  */
 public function getByModel(Request $request)
 {
     $attachments = Attachment::getByModel($request->get('model'), $request->get('model_id'), $request->get('context'));
     return response()->json($attachments);
 }