Usage with Larupload
Follow these steps to set up Larupload and integrate it with your project:
Install Larupload using this documentation
Add Larupload Columns to Your Table:
In your migration file, add Larupload columns to your table. Here's an example:
<?php
use Mostafaznv\Larupload\Enums\LaruploadMode;
class CreateMediaTable extends Migration
{
public function up()
{
Schema::create('media', function (Blueprint $table) {
$table->id();
$table->upload('video', LaruploadMode::LIGHT);
$table->timestamps();
});
}
}
Add Larupload Trait to Your Model:
Next, add the Larupload trait to your model. Define upload entities as needed. Here's an example:
<?php
namespace App\Models;
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
use Mostafaznv\Larupload\Enums\LaruploadMode;
use Mostafaznv\Larupload\Enums\LaruploadNamingMethod;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;
class Media extends Model
{
use Larupload;
public function attachments(): array
{
return [
Attachment::make('video', LaruploadMode::LIGHT)
->namingMethod(LaruploadNamingMethod::HASH_FILE)
->coverStyle('cover', 852, 480, LaruploadMediaStyle::AUTO)
];
}
}
Add NovaVideo Field to Your Resource:
In your Nova resource, add the NovaVideo
field for the video column. Configure it as needed. Here's an example:
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Mostafaznv\NovaVideo\Video;
use App\Models\Media as MediaModel;
class Media extends Resource
{
public static string $model = MediaModel::class;
public function fields(Request $request): array
{
return [
ID::make()->sortable(),
Video::make(trans('Video'), 'video')
->storeWithLarupload()
->rules('file', 'max:150000', 'mimes:mp4', 'mimetypes:video/mp4')
->creationRules('required')
->updateRules('nullable'),
];
}
}
Last updated