1. Go to this page and download the library: Download digitaldream/photo library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function photo()
{
return $this->belongsTo(\Photo\Models\Photo::class, 'photo_id');
}
/**
* @var \Photo\Repositories\PhotoRepository
*/
protected $photoRepository;
public function __construct(PhotoRepository $photoRepository)
{
$this->photoRepository = $photoRepository;
}
public function store(StoreRequest $request)
{
//Your other code.
$post->photo_id = $this->photoRepository->create($file, ['caption' => $data['title']])->id;
}
namesapce App\Repositories;
class PostRepository
{
/**
* @var \Photo\Services\PhotoService
*/
protected PhotoService $photoService;
public function __construct(PhotoService $photoService)
{
$this->photoService = $photoService;
}
public function store(Request $request)
{
$post = new Post();
$post->fill($request->all());
$mainImageFolder = "posts"
$thumbnailWidth = 220;
$thumbnailHheight= 200;
$crop="no"; // "yes" will resize image automatically based on your maximum height,width.
$thumbnailPath = "thumbnails"; // Thumbnails path are relative to main Image folder.
//In this case it will create a folder thumbnails under posts folder.
$post->image = $this->photoService
->setDimension($thumbnailWidth, $thumbnailHheight, $thumbnailPath)
->store($mainImageFolder, $request->file('file'), $post->title, $crop)
->convert()
->getStoredImagePath();
$post->save();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.