ctf0 / Laravel-Media-Manager

A "Vuejs & Laravel" Media Manager With Tons of Features
MIT License
829 stars 179 forks source link

Laravel-Media-Manager's route not found if different URL/Route names used #54

Closed WalkingInTheDarkness closed 5 years ago

WalkingInTheDarkness commented 5 years ago

What version of Laravel are you using? (nothing lower than v5.4).

L5.6

is it an issue related to installation or usage ?

Usage

what is the error you are getting ?

Route [media.files] not defined. (View: /Volumes/users/artur/WebDesign/ValetSites/moeera-cms/resources/views/vendor/MediaManager/_manager.blade.php

Extra Info "attaching a screen shot would be very helpful"

With ctf0\MediaManager\MediaRoutes::routes(); as placed into /routes/web.php by installation script (which results with: url like: media/action and route names like: media.action), everything (as far I checked) works. However if I decide to move this into some 'Route::group' to have access restricted for admins/authors (which results with: url like: manage/media/action and route names like: manage::media.action) going to manage/media results with error as above

larmedia-1

larmedia-2

Can this be fixed by changing some configuration variable (but judging by names - not) or is the only way to change this (in _manager.blade.php):

:routes="{{ json_encode([
        'files' => route('media.files'), 
        'dirs' => route('media.directories'), 
        'lock' => route('media.lock_file'), 
        'visibility' => route('media.change_vis'), 
    ]) }}"

to this:

:routes="{{ json_encode([
        'files' => route('manage::media.files'), 
        'dirs' => route('manage::media.directories'), 
        'lock' => route('manage::media.lock_file'), 
        'visibility' => route('manage::media.change_vis'), 
    ]) }}"

EDIT: There are several other places in the template where route() helper is used (like <form action> attributes). Changing route names provided to route() helper sorted out the problem. Question remains - is this the only way to achieve this? (EDIT 2 - no, it did not, only looked like this) Thanks!

ctf0 commented 5 years ago

thats the problem, dont change the route names, i also have a very similar setup where i nest the manager routes under the admin url but without affecting the name. ex

Route::group(['middleware' => ['admin']], function () {
    // ...

    // "url: admin/"
    Route::group(['prefix' => 'admin'], function () {
        ctf0\MediaManager\MediaRoutes::routes();

        // "name: admin."
        Route::group(['as' => "admin."], function () {
            // ...
        });
    });
});

updating the route names of the manager will cuz u nothing but a big headache

WalkingInTheDarkness commented 5 years ago

So, basically, URL can be changed in any way as long as the route names are kept untouched and everything will work smoothly?

ctf0 commented 5 years ago

exactly 👍

WalkingInTheDarkness commented 5 years ago

Thanks for quick reply, appreciate ;-)

WalkingInTheDarkness commented 5 years ago

I have done what advised: /routes/web.php:

/** Dashboard routes **/

Route::middleware([
    'auth',
])->group(function() {

    /** Routes available for authenticated users only **/

    Route::group([
        'prefix' => 'manage',
        /** Do not change route names as that will break MediaManager **/
    ], function() {

        Route::group([
            'middleware' => 'role:superadministrator|administrator|editor|author',
        ], function() {
            // MediaManager
            ctf0\MediaManager\MediaRoutes::routes();
        });
    });

    Route::group([
        'prefix' => 'manage',
        'as' => 'manage::',
    ], function() {

        Route::group([
            'middleware' => 'role:superadministrator|administrator|editor|author|user',
        ], function() {
    (...)

but the problem I am facing now - image thumbnails are not displayed now:

larmedia-5

quick check of image src attribute and 'manage' bit is being added:

<img src="http://moeera-cms.test/storage/manage/pages/AI1ITePFhXEcmKCPEdOqDx9zMy0fZIFkXMG4Flyb.jpeg" 

while the real path to image file is http://moeera-cms.test/storage/pages/AI1ITePFhXEcmKCPEdOqDx9zMy0fZIFkXMG4Flyb.jpeg

How can I fix this?

WalkingInTheDarkness commented 5 years ago

@ctf0 - could you please reopen it, it's not sorted out as you can see above.

ctf0 commented 5 years ago

have u updated the .env APP_URL = http://moeera-cms.test ? also what is the error in the console ?

try to long press the manager refresh btn and see if it fixes the issue for u.

WalkingInTheDarkness commented 5 years ago

yes, I have replaced APP_URL = localhost, that was first thing I noticed after I installed Laravel-Media-Manager. There are no errors in the console, just wrong string is provided to <img src (__stack-files, file preview) and to <a href (__sidebar-info, public URL) attributes. They came from file.path and selectedFile.path Vue props.

WalkingInTheDarkness commented 5 years ago

I have looked in Vue Developer Tool and baseUrl is correct but it looks like paths are computed incorrectly:

larmedia-6

larmedia-7

larmedia-8

ctf0 commented 5 years ago

can u show me a screenshot for the console error ?

also am not really sure where the manage path come from, check your storage path and make sure you cleared the browser cache just to be on the safe side

WalkingInTheDarkness commented 5 years ago

manage is a Route prefix

WalkingInTheDarkness commented 5 years ago

Console: larmedia-9

ctf0 commented 5 years ago

the route prefix shouldnt affect the storage path, can u make a repo with ur setup and send me a link to test ?

WalkingInTheDarkness commented 5 years ago

@ctf0 it had to be some cache issue, I have cleared everything, view, routes, config cache, browser cache and restarted nginx. Reinstalled Laravel-Media-Laravel and now it works, even with added URL prefix. Thanks for your help