简体   繁体   中英

LARAVEL 5.2 Routing Object Not Found

i usually use development laravel with artisan, but in this case i must set laravel in lampp. i have route like

Route::group(['middleware' => 'cors', 'prefix' => 'service'], function () {

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

    Route::resource('produk', 'Master\ProdukController');
    Route::resource('agama', 'Master\AgamaController');
  });
Route::resource('list-generic', 'ListGeneric', ['only' => ['index']]);
});

and my .htacess in public folder:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

my problem is. when i access this link:

http://172.16.16.1/a-web/service/list-generic?select=id

it perfectly work, but when i access with this link with "/" after list-generic:

http://172.16.16.1/a-web/service/list-generic/?select=id

show error object not found, please need help..

This must be because of your route file.
When you add
Route::resource('list-generic', 'ListGeneric', ['only' => ['index']]);
Laravel will only use the route

http://172.16.16.1/a-web/service/list-generic

and Not

http://172.16.16.1/a-web/service/list-generic/

for the above route to work you will have to add the optional parameter to the route

Route::resource('list-generic/{?query}', 'ListGeneric', ['only' => ['index']]);

This route will handle all both type of links.

i have found solution for my own question. finally i must edit .httaccess file:

Options -MultiViews
RewriteEngine On
RewriteBase /a-web/

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ $1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM