GithubHelp home page GithubHelp logo

rmoorman / laravel-trailing-slash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fsasvari/laravel-trailing-slash

0.0 2.0 0.0 53 KB

Adds redirection with trailing slash in Laravel.

License: MIT License

PHP 100.00%

laravel-trailing-slash's Introduction

Laravel Trailing Slash

Adds url formatting and redirection with trailing slash to Laravel 7.x, 6.x and 5.x.

Build For Laravel Latest Stable Version Latest Unstable Version Total Downloads License

Compatibility Chart

Laravel Trailing Slash Laravel PHP
2.x 7.x 7.3+
1.x 6.x 7.2+
0.3.x 5.7-5.8 7.1.3+
0.2.x 5.6 7.1.3+
0.1.x 5.5 7.0.0+

Installation

Step 1: Install package

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": "2.*"

Step 2: Service Provider

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,
    // ...
],

Step 3: .htaccess

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>

Step 4: Routes

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');
});

Usage

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');

Change log

Please see CHANGELOG for more information what has changed recently.

Notice

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();

Licence

MIT Licence. Refer to the LICENSE file to get more info.

Author

Frano Šašvari

Email: [email protected]

laravel-trailing-slash's People

Contributors

fsasvari avatar devdavido avatar sailingdeveloper avatar waynebrummer avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.