Package Data | |
---|---|
Maintainer Username: | fsasvari |
Maintainer Contact: | sasvari.frano@gmail.com (Frano Sasvari) |
Package Create Date: | 2017-01-23 |
Package Last Update: | 2024-03-02 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-14 15:09:36 |
Package Statistics | |
---|---|
Total Downloads: | 142,422 |
Monthly Downloads: | 1,723 |
Daily Downloads: | 21 |
Total Stars: | 58 |
Total Watchers: | 3 |
Total Forks: | 17 |
Total Open Issues: | 7 |
Adds redirection with trailing slash to Laravel 5.7.
| Laravel Trailing Slash | Laravel | PHP | |----------------------------------------------------------------------|-----------|---------| | 0.3.x | 5.7 | 7.1.3+ | | 0.2.x | 5.6 | 7.1.3+ | | 0.1.x | 5.5 | 7.0.0+ |
To get started with Laravel Trailing Slash, use Composer command to add the package to your composer.json project's dependencies:
composer require fsasvari/laravel-trailing-slash
Or add it directly by copying next line into composer.json:
"fsasvari/laravel-trailing-slash": "0.3.*"
After installing the Laravel Trailing Slash library, register the LaravelTrailingSlash\RoutingServiceProvider
in your config/app.php
configuration file:
'providers' => [
// Application Service Providers...
// ...
// Other Service Providers...
LaravelTrailingSlash\RoutingServiceProvider::class,
// ...
],
Copy following redirection code from public/.htaccess
to your own project:
<IfModule mod_rewrite.c>
# Redirect To Trailing Slashes If Not A Folder Or A File...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
</IfModule>
In routes/web.php, you must use routes with trailing slashes now:
Route::get('/', function () {
return view('welcome');
});
Route::get('about/', function () {
return view('about');
});
Route::get('contact/', function () {
return view('contact');
});
Every time you use some Laravel redirect function, trailing slash ("/") will be applied at the end of url.
return redirect('about/');
return back()->withInput();
return redirect()->route('text', ['id' => 1]);
return redirect()->action('IndexController@about');
Please see CHANGELOG for more information what has changed recently.
There is a problem with overriding Laravel's Paginator
and LengthAwarePaginator
classes. So, every time you use paginate()
method on your models, query builders etc., you must set current path for pagination links. Example:
$texts = Text::where('is_active', 1)->paginate();
$texts->setPath(URL::current());
$texts->links();
MIT Licence. Refer to the LICENSE file to get more info.
Frano Šašvari
Email: sasvari.frano@gmail.com