Skip to content

Instantly share code, notes, and snippets.

@gavinhewitt
Last active March 9, 2022 09:46
Show Gist options
  • Save gavinhewitt/f623b6bfef92842c5b4278b09ca88825 to your computer and use it in GitHub Desktop.
Save gavinhewitt/f623b6bfef92842c5b4278b09ca88825 to your computer and use it in GitHub Desktop.
Default RouteServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
public const HOME = '/home';
protected $namespace = 'App\\Http\\Controllers';
public function boot()
{
$this->routes(function () {
$this->removeIndexPhpFromUrl();
$this->frontendRoutes();
$this->apiRoutes();
if (app()->environment('local')) {
$this->devRoutes();
}
});
}
// https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/
protected function removeIndexPhpFromUrl()
{
if (Str::contains(request()->getRequestUri(), '/index.php/')) {
$url = str_replace('index.php/', '', request()->getRequestUri());
if (strlen($url) > 0) {
header("Location: $url", true, 301);
exit;
}
}
}
protected function frontendRoutes()
{
// Auth::routes();
Route::middleware('frontend')
->namespace($this->namespace)
->group(function() {
Route::get('/', \ShowLanding::class)->name('home');
});
}
protected function apiRoutes()
{
Route::prefix('api/v1')
->namespace($this->namespace)
->group(function() {
Route::get('search/{query}', \Api\Search::class);
});
}
protected function devRoutes()
{
Route::prefix('dev')
->group(function() {
Route::view('/', 'dev/new');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment