이렇게 '여행'과 '사진'의 두 가지 모델이 있습니다.
public function pictures(){
return $this->hasMany('Picture');
}
그런 다음, 사진 모델, 당신은 스테이플러 첨부 정의 : 당신 이제
// Be sure and use the stapler trait, this will not work if you don't:
use Codesleeve\Stapler\Stapler;
// In your model's constructor function, define your attachment:
public function __construct(array $attributes = array()) {
// Pictures have an attached file (we'll call it image, but you can name it whatever you like).
$this->hasAttachedFile('image', [
'styles' => [
'thumbnail' => '100x100#',
'foo' => '75x75',
'bar' => '50x50'
]
]);
parent::__construct($attributes);
}
를 '당신의 여행 모델에서는 사진 모델로'hasMany의 '관계를 정의 할 필요가 그림 모델에서 첨부 파일을 정의 했으므로 Picture 개체에 액세스 할 때마다 파일 첨부에 액세스 할 수 있습니다. 당신이 여행 기록을 가지고 가정하면, 당신이 할 수 있습니다 :
<img src="<?= asset($picture->image->url()) ?>">
// or
<img src="<?= asset($picture->image->url('original')) ?>">
는 사실, 당신은 당신이 정의 된 스타일에 액세스 할 수 있습니다 :
<?php foreach ($trip->pictures as $picture): ?>
<img src="<?= asset($picture->image->url('thumbnail')) ?>">
<?php endforeach ?>
는이 같은 원본 이미지에 액세스 할 수 있습니다
<img src="<?= asset($picture->image->url('foo')) ?>">
<img src="<?= asset($picture->image->url('bar')) ?>">
희망이 도움이됩니다.