Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ignaaaam's avatar

Links pagination redirecting me to index instead of keeping url

Hello, there's something strange happening with my pagination that never seen before. If i'm on index, page pagination works as it should (it adds ?page=2 to the url and works correctly). But if i'm in the admin dashboard (url has admin/discounts) instead of adding ?page=2 to that url (so it should be admin/discounts?page=2) it redirects me to /index.php?page=2. It's strange because in development (localhost) worked fine, but in deployment (using Heroku) this happens. Does someone knows what could be causing it? I'm using <div class="links p-8">{{ $discounts->appends(request()->input())->links() }}</div> first I had $discounts->links() but i'm searching ways of fixing this or what could be causing the issue.

0 likes
8 replies
MohamedTammam's avatar

Do you have a custom pagination view? how are you getting your result from database?

ignaaaam's avatar

@MohamedTammam I just tweaked the css a bit of the pagination (using vendor:publish) and I get the results like is done in any controller. But I dont think it has nothing to do with this. Because it works on local but not when it's deployed to Heroku.

AdminDiscountController

<?php

namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\Discount;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class AdminDiscountController extends Controller
{
    public function index()
    {
        return view('admin.discounts.index', [
            'discounts' => Discount::paginate(5)
        ]);
    }

    public function create()
    {
        return view('admin.discounts.create', [
            'categories' => Category::all()
        ]);
    }

    public function store()
    {
        $originalPrice = request('original_price');
        $discountedPrice = request('discounted_price');
        $percentage = 100 * ($originalPrice - $discountedPrice) / $originalPrice;

        $link = parse_url(request()->input('link'), PHP_URL_SCHEME) ? request()->input('link') : 'https://' . request()->input('link');

        Discount::create(array_merge($this->validateDiscount(), [
            'user_id' => request()->user()->id,
            'thumbnail' => request()->file('thumbnail')->store('discount_thumbnails'),
            'percentage' => $percentage,
            'premium' => 0,
            'link' => $link
        ]));

        return redirect('/')->with('success', 'Descuento creado con exito!');
    }


    protected function validateDiscount(?Discount $discount = null): array
    {
        $discount ??= new Discount();
        $originalPrice = request('original_price');
        $discountedPrice = request('discounted_price');
        $percentage = 100 * ($originalPrice - $discountedPrice) / $originalPrice;

        return request()->validate([
            'title' => 'required',
            'thumbnail' => $discount->exists ? ['image'] : ['required', 'image'],
            'slug' => ['required', Rule::unique('discounts', 'slug')->ignore($discount)],
            'body' => 'required',
            'original_price' => 'required|numeric|gt:discounted_price',
            'discounted_price' => 'required|numeric|lt:original_price',
            'category_id' => ['required', Rule::exists('categories', 'id')],
            'link' => 'required',
        ]);
    }

    public function edit(Discount $discount)
    {
        $categories = Category::all();
        return view('users.discounts.edit', [
            'discount' => $discount,
            'categories' => $categories
        ]);
    }

    public function update(Discount $discount) {
        $attributes = $this->validateDiscount($discount);

        if($attributes['thumbnail'] ?? false) {
            $attributes['thumbnail'] = request()->file('thumbnail')->store('discounts_thumbnail');
        }

        $discount->update($attributes);

        return back()->with('success', 'Descuento actualizado!');
    }

    public function destroy(Discount $discount)
    {
        $discount->delete();

        return back()->with('success','Descuento eliminado!');
    }
}
ignaaaam's avatar

@MohamedTammam By the way if I add the url manually the ?page=2 works for admin/discounts it's just it redirects me to index?page=2 for no reason when it shouldnt.

ignaaaam's avatar

@MohamedTammam The URLS are okay. I think its what people said about .htaccess i'll update later if it's that or not. Thanks anyways.

Snapey's avatar

seems like something funky with .htaccess

ignaaaam's avatar

@Snapey Oh didnt tought about it, it must be something like this I guess.

This is what i have at the moment, i'll see later if it's this what causes it because it's what has more sense to be causing the error.

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

    RewriteEngine On

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

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

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

    #add this on public/.htaccess for Laravel
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Please or to participate in this conversation.