PHP code example of dcodegroup / laravel-attachments
1. Go to this page and download the library: Download dcodegroup/laravel-attachments 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/ */
dcodegroup / laravel-attachments example snippets
Schema::create('media', function (Blueprint $table) {
...
$table->nullableMorphs('model');
$table->nullableMorphs('parent_model');
Schema::create('media', function (Blueprint $table) {
...
$table->nullableUlidMorphs('model');
$table->nullableUlidMorphs('parent_model');
use Illuminate\Support\Facades\Route;
Route::attachments();
Route::attachmentAnnotations();
Route::attachmentCategories();
namespace App\Policies;
use App\Models\User;
use Dcodegroup\LaravelAttachments\Models\Media;
use Illuminate\Auth\Access\HandlesAuthorization;
class MediaPolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
return $this->internalOnly($user);
}
public function view(User $user, Media $media): bool
{
return $this->internalOnly($user);
}
public function create(User $user): bool
{
return $this->internalOnly($user);
}
public function update(User $user, Media $media): bool
{
return $this->internalOnly($user);
}
public function delete(User $user, Media $media): bool
{
return $this->internalOnly($user);
}
public function restore(User $user, Media $media): bool
{
return $this->internalOnly($user);
}
public function forceDelete(User $user, Media $media): bool
{
return $this->internalOnly($user);
}
}
use Dcodegroup\LaravelAttachments\Contracts\HasMediaUser;
class User extends Authenticatable implements HasMediaUser
{
...
public function getMediaUserName(): string
{
return $this->name;
}