Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed Oct 30, 2024
1 parent 79663e7 commit 96c2484
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 21 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Add redirects to your Laravel app using a database, so you can edynamically manage it without writing code.
# Laravel Redirects

## Add redirects to your Laravel app using a database, so you can dynamically manage it without writing code.

[![Latest Version on Packagist](https://img.shields.io/packagist/v/vormkracht10/laravel-redirects.svg?style=flat-square)](https://packagist.org/packages/vormkracht10/laravel-redirects)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/vormkracht10/laravel-redirects/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/vormkracht10/laravel-redirects/actions?query=workflow%3Arun-tests+branch%3Amain)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vormkracht10/laravel-redirects",
"description": "Add redirects to your Laravel app using a database, so you can edynamically manage it without writing code.",
"description": "Add redirects to your Laravel app using a database, so you can dynamically manage it without writing code.",
"keywords": [
"Vormkracht10",
"laravel",
Expand Down
40 changes: 39 additions & 1 deletion config/redirects.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
<?php

// config for Vormkracht10/Redirects
return [
/*
* The available status codes for redirection.
*/
'status_codes' => [
// 300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
// 303 => 'See Other',
// 304 => 'Not Modified',
// 305 => 'Use Proxy',
// 306 => 'Unused',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
],

/*
* The default status code to select when redirecting.
*/
'default_status_code' => env('REDIRECT_DEFAULT_STATUS_CODE', 301),

/*
* If the case is sensitive, the following routes will be treated as different:
*
* /example
* /Example
*/
'case_sensitive' => env('REDIRECT_CASE_SENSITIVE', false),

/*
* If the trailing slash is sensitive, the following routes will be treated as different:
*
* /example
* /example/
*/
'trailing_slash_sensitive' => env('REDIRECT_TRAILING_SLASH_SENSITIVE', false),

/*
* Always add a trailing slash for redirect endpoint to maintain consistency in used URLs for SEO.
*/
'trailing_slash' => env('REDIRECT_WITH_TRAILING_SLASH', false),
];
16 changes: 10 additions & 6 deletions database/migrations/create_redirects_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('laravel_redirects_table', function (Blueprint $table) {
$table->id();

// add fields

Schema::create('redirects', function (Blueprint $table) {
$table->ulid()->primary();
$table->string('path');
$table->string('destination')->nullable();
$table->unsignedInteger('code', 3)->default(301)->autoIncrement(false);
$table->unsignedBigInteger('hits')->default(0);
$table->timestamps();
});
}
Expand Down
14 changes: 14 additions & 0 deletions src/Models/Redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Vormkracht10\Redirects\Models;

use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Redirect extends Model
{
use HasFactory, HasUlids;

protected $primaryKey = 'ulid';
}
5 changes: 0 additions & 5 deletions src/Redirects.php

This file was deleted.

8 changes: 1 addition & 7 deletions src/RedirectsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ class RedirectsServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
/*
* This class RedirectsServiceProvider a Package Service Provider
*
* More info: https://github.com/spatie/laravel-package-tools
*/
$package
->name('laravel-redirects')
->hasConfigFile()
->hasViews()
->hasMigration('create_laravel_redirects_table')
->hasCommand(RedirectsCommand::class);
->hasMigration('create_laravel_redirects_table');
}
}

0 comments on commit 96c2484

Please sign in to comment.