PHP code example of mostafaznv / nova-larupload

1. Go to this page and download the library: Download mostafaznv/nova-larupload 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/ */

    

mostafaznv / nova-larupload example snippets




use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Mostafaznv\Larupload\Enums\LaruploadMode;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('attachments', function (Blueprint $table) {
            $table->id();
            $table->string('title')->nullable();
            $table->upload('main_file', LaruploadMode::HEAVY);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('attachments');
    }
};



namespace App\Models;

use FFMpeg\Format\Video\X264;
use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
use Mostafaznv\Larupload\Enums\LaruploadMode;
use Mostafaznv\Larupload\Traits\Larupload;
use Mostafaznv\Larupload\Storage\Attachment as LaruploadAttachment;


class Attachment extends Model
{
    use Larupload;

    public function attachments(): array
    {
        return [
            LaruploadAttachment::make('main_file')
                ->image('thumbnail', 640, 480)
                ->image('retina', 1280, 960)
                ->video('SD', 640, 480)
                ->video('HD', 1920, 1080)
                ->stream(
                    name: '480p',
                    width: 640,
                    height: 480,
                    format: (new X264)
                        ->setKiloBitrate(1000)
                        ->setAudioKiloBitrate(32)
                )
                ->stream(
                    name: '720p',
                    width: 1280,
                    height: 720,
                    format: (new X264)
                        ->setKiloBitrate(3000)
                        ->setAudioKiloBitrate(64)
                )
        ];
    }
}




namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use App\Models\Attachment as Model;
use Mostafaznv\NovaFileArtisan\Fields\NovaFileArtisan;


class Attachment extends Resource
{
    public static string $model = Model::class;

    public static $title = 'title';


    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            Text::make('Title')->rules('
  


namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use App\Models\Attachment as Model;
use Mostafaznv\NovaFileArtisan\Fields\NovaFileArtisan;
use Mostafaznv\NovaFileArtisan\Fields\NovaFileArtisanMeta;


class Attachment extends Resource
{
    public static string $model = Model::class;

    public static $title = 'title';


    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            Text::make('Title')->rules('('main_file')->duration(),
            NovaFileArtisanMeta::make('main_file')->format(),
        ];
    }
}
  


namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
use App\Models\Attachment as Model;
use Mostafaznv\NovaFileArtisan\Fields\NovaFileArtisan;


class Attachment extends Resource
{
    public static string $model = Model::class;

    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            NovaFileArtisan::make('Main File', 'main_file')
                ->hideCoverUploader(),
        ];
    }
}
  


namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
use App\Models\Attachment as Model;
use Mostafaznv\NovaFileArtisan\Fields\NovaFileArtisan;


class Attachment extends Resource
{
    public static string $model = Model::class;

    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            NovaFileArtisan::make('Main File', 'main_file')
                ->hideCoverFromDetail(),

            // or you can hide cover from detail based on condition
            
            NovaFileArtisan::make('Main File', 'main_file')
                ->hideCoverFromDetail(
                    fn (NovaRequest $request) => $request->resourceId == 34
                ),
        ];
    }
}
shell
php artisan vendor:publish --provider="Mostafaznv\NovaFileArtisan\NovaFileArtisanServiceProvider"