Closed Quix0r closed 4 years ago
route()
has the large advantage that Laravel can make sure that the route does actually exist given you an earlier chance to find invalid URLs/routes while url()
does only make sure that the URL is dynamically generated (based on your base URL).
If you can provide a PR with the necessary changes, we would love to integrate them into the aimeos-laravel package :-)
@aimeos is this issue still open? The paths in this package already use the route helper except in 2 places (login and logout link).
It still doesn't fully work and we don't know why because we only use the Laravel router
Can you please tell me what's not working? I'm currently setting up an online shop and would love to use this. I'd also create a PR with a fixed version if you could tell me what's not working right now.
If you have Aimeos installed in a subfolder, the links to the detail page doesn't contain that subfolder but to the root directory instead (/product_name instead of /subfolder/product_name)
BTW: All links are generated here: https://github.com/aimeos/ai-laravel/blob/master/lib/custom/src/MW/View/Helper/Url/Laravel5.php#L61
Hmmm I'm unable to get it working using MAMP on Mac and a PHP socket. Laravel works, migrations do work too but the php artisan aimeos:setup
command is unable to connect to the database. Looks like it's ignoring the socket setting and directly connecting to the ip address and port.
Hm, maybe the default settings prevent the MySQL client to use the socket: https://github.com/aimeos/aimeos-laravel/blob/master/src/default.php#L31
I'm not sure, the output looks ok so far (added a print_r in SetupCommand.php on line 61 right after the $dbconfig = ...
thing):
Array
(
[db] => Array
(
[adapter] => mysql
[host] => 127.0.0.1
[port] => 3306
[socket] => /Applications/MAMP/tmp/mysql/mysql.sock
[database] => shop
[username] => shop
[password] => shop
[stmt] => Array
(
[0] => SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'
)
[opt-persistent] => 0
[limit] => 3
[defaultTableOptions] => Array
(
[charset] => utf8mb4
[collate] => utf8mb4_unicode_ci
)
)
)
If host and port are set, they are used instead of the socket I think
Ok that did the trick, thanks! 👍
Tried tracking this down...
Let's assume our URL to aimeos is like this: https://www.domain.com/shop/public/shop
Protocol: https
Route domain: www.domain.com
Path: /shop/public/shop
The symfony http-foundation/Request.php method prepareBaseUrl() returns the path to your public folder: https://github.com/symfony/http-foundation/blob/master/Request.php#L1747-L1809
Resulting in /shop/public
.
Laravel itself uses the result from the symfony http-foundation/Request.php getBaseUrl() method above (/shop/public
) and strips it from the path (/shop/public/shop
) by using ltrim which results in /shop
.
Method to(...) here: https://github.com/laravel/framework/blob/master/src/Illuminate/Routing/RouteUrlGenerator.php#L77-L110
So, absolute URLs like the assets or the data attributes for the json api do work, but relative ones do not because of the things from above. Also setting a <base href="/shop/public">
doesn't help as Laravel prefixes every relative url with a /
.
A possible solution would be to check if we are on a subdirectory and if so, overwrite the laravel core functionality to generate the relative urls.
An alternate solution would be to just remove the /
with ltrim() before returning the string in your Laravel5.php transform() method and adding a <base href="/shop/public">
in your app.blade.php
file (just strip everything domain related from the APP_URL
value in the .env file and set the base href tag automatically to the resulting string).
Seems like a Laravel issue but why does subdirectories work in other Laravel based applications without problems?
Do you have an example for a project where it's working?
Referring to that post: https://aimeos.org/help/help-f15/incorrect-url-path-with-multiple-apache-alias-t1955.html
If you install (same for admin interface) the shop under a sub path, like
/myshop/
only the index pages (dashboard in admin) work, but not any sub page. This is because of a static/
is being used all over the place. Instead, you should useroute()
or at leasturl()
for dynamically generating URLs.Not all people will have the option of having your shop being installed in document root directory.