amaelftah/laravel-trix

File upload issue

simongeau opened this issue · 6 comments

I can't get file upload working (the rest is working fine) Am I doing something wrong?

In the blade file

<form method="POST" action="{{ $endpoint }}" enctype='multipart/form-data'>
            @csrf
            <input type="hidden" name="_method" value="{{ isset($post->id) ? 'PATCH' : 'POST' }}">
           @trix($post, 'content')
            <button class="btn btn-primary" type="submit">{{ __('Save') }}</button>
        </form>

In the controller


    public function update(Request $request, Post $post)
    {
        $post->update(request()->all());
        return redirect("/posts/");
    }

In the Model

namespace App;

use Illuminate\Database\Eloquent\Model;
use Te7aHoudini\LaravelTrix\Traits\HasTrixRichText;

class Post extends Model
{
    use HasTrixRichText;
    protected $fillable = ['titre'];
}

@smdimagerie do you mean file upload outside trix editor or inside trix editor ?

inside the editor; when I upload a photo it shoes in the editor. But when I press save, the file is not added to the storage. So then I re open the content of the editor I get a broken image.

@smdimagerie are you sure that storage configurations are correct ?

Storing Attachment

Ok found some issues (i'm on a windows machine, but I guess that applies to unix based system)

TrixAttachmentController.php
$attachment = $request->file->store('/', $request->disk ?? config('laravel-trix.storage_disk'));;

why is there a slash? Removing it made me store the file
$attachment = $request->file->store($request->disk ?? config('laravel-trix.storage_disk'));;


Now I'm trying to get the public folder out of the equation:

the file is stored as
/storage/public/filename.ext

then the url is returned as
/storage/public/filename.ext

but the symlink created using php artisan storage:link is between /storage/public/filename.ext and /storage/filename.ext so the retrival doesn't work

Splitted
$url = Storage::disk($request->disk ?? config('laravel-trix.storage_disk'))->url($attachment);

as

// Store
Storage::disk($request->disk ?? config('laravel-trix.storage_disk'));
// Generate a URL
$url = Storage::url($attachment);

@smdimagerie ok cool i will close it since it's fixed now