v8 to v9 - Steps: Please confirm this #2919
Unanswered
metacraft-hq
asked this question in
Q&A
Replies: 2 comments
-
Upload works but URL not found for image?
|
Beta Was this translation helpful? Give feedback.
0 replies
-
this is what I have added to my project: Upload works but URL not found for image?
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateMediaTable extends Migration
{
public function up()
{
Schema::create('media', function (Blueprint $table) {
$table->bigIncrements('id');
$table->morphs('model');
$table->uuid('uuid')->nullable()->unique();
$table->string('collection_name');
$table->string('name');
$table->string('file_name');
$table->string('mime_type')->nullable();
$table->string('disk');
$table->string('conversions_disk')->nullable();
$table->unsignedBigInteger('size');
$table->json('manipulations');
$table->json('custom_properties');
$table->json('generated_conversions');
$table->json('responsive_images');
$table->unsignedInteger('order_column')->nullable()->index();
$table->nullableTimestamps();
});
}
}
<?php
namespace App\Http\Controllers;
use App\Models\Media;
use Illuminate\Http\Request;
class MediaController extends Controller
{
public function create ()
{
return view('folders.create'); //might need to tie this to my folder.create
}
public function store ()
{
/** @var Media $media */
$media = Media::create();
$media
->addMediaFromRequest('media')
->toMediaCollection('media');
return back();
}
}
'disks' => [
'media' => [
'driver' => 'local',
'root' => public_path('media'),
'url' => env('APP_URL').'/media',
],
/*
* The disk on which to store added files and derived images by default. Choose
* one or more of the disks you've configured in config/filesystems.php.
*/
'disk_name' => 'media',
use App\Http\Controllers\Media\Controller;
use App\Models\Media;
// SPATIE MEDIA v8 to v9
Route::get('add-media-to-library', function () {
Media::create()
->addMedia(storage_path('media/'))
->toMediaCollection();
});
Route::get('add-media-from-request', [MediaController::class, 'create']);
Route::post('add-media-from-request', [MediaController::class, 'store']);
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Media extends Model implements HasMedia
{
use HasFactory;
use InteractsWithMedia;
public static function last()
{
return static::all()->last();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, so created a project which is using
spatie/laravel-medialibrary
After running
composer update
my add media function is giving me the error and need to update my files:I have read through these links:
https://github.com/spatie/laravel-medialibrary/blob/main/UPGRADING.md
https://spatie.be/docs/laravel-medialibrary/v9/introduction
YET, I am still learning so I followed this :
https://spatie.be/courses/discovering-laravel-media-library/adding-and-retrieving-media
I really want to get this function back so...
PLEASE (IF YOU DONT MIND) -- See below what I have compiled from the Spatie Website Video on MediaLibrary and help me ensure I get this right. Thank you
STEPS:
create M&C
php artisan make:model Article -c
// MEDIA - AIFX - SPATIE UPGRADE
web.php
App\Models\Article
config\media-library.php
php artisan vendor:publish
13
You should see something like this...
$table->json('generated_conversions');
Back to:
config\media-library.php
config\filesystems.php
App\Http\Controllers\Article\Controller
Beta Was this translation helpful? Give feedback.
All reactions