Ejemplo n.º 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();
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 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);
 }