1. Go to this page and download the library: Download akatekno/attachable 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/ */
akatekno / attachable example snippets
namespace App\Models;
use Akatekno\Attachable\Interfaces\AttachableOne;
use Akatekno\Attachable\Traits\AttachableOne as TraitsAttachableOne;
class User implements AttachableOne
{
use TraitsAttachableOne;
// ... the rest of the code
}
use App\Models\User;
class Controller
{
public function index()
{
return User::first()->attachment;
}
}
namespace App\Models;
use Akatekno\Attachable\Interfaces\AttachableMany;
use Akatekno\Attachable\Traits\AttachableMany as TraitsAttachableMany;
class User implements AttachableMany
{
use TraitsAttachableMany;
// ... the rest of the code
}
use App\Models\User;
class Controller
{
public function index()
{
return User::first()->attachments;
}
}
namespace App\Models;
use Akatekno\Attachable\Models\Attachment;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
class Reservation extends Model
{
// ...
public function visit_request_letter(): MorphOne
{
return $this->morphOne(Attachment::class, 'attachable')
->where('type', 'visit-request-letter');
}
public function hotel_booking_invoice(): MorphOne
{
return $this->morphOne(Attachment::class, 'attachable')
->where('type', 'hotel-booking-invoice');
}
public function other_attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachable')
->where('type', 'other-attachment');
}
// ...
}