589 questions
1
vote
0
answers
103
views
Problems reading my own cookie in other parts of my Laravel app
I have a simple form where users come to report who they helped, and how. It is anonymous in the fact that they do not have to login in, but they are asked to provide their name. They will make many ...
1
vote
0
answers
57
views
Laravel headers multiple location error while redirecting on localhost
Getting this when redirected from the controller or middleware, just cloned this project from the live server to the local machine.
have also tried this php artisan serve but still facing the same ...
1
vote
2
answers
99
views
Admin middleware does not work properly in Laravel
I have made a middleware for admin routes
public function handle(Request $request, Closure $next)
{
if (!auth()->check() || !auth()->user()->is_admin) {
abort(401);
}
...
0
votes
0
answers
83
views
How can we block access to a website from HTTPS clients like Postman and cURL?
We are using Laravel and trying to update the Cors.php middleware, but it's not working.
Here is the Cors.php code
public function handle($request, Closure $next)
{
if (null !== $...
0
votes
1
answer
89
views
Auth check return false in middleware, but should return true with Log Viewer
I installed Log Viewer in my laravel 11 protect, and works like a charm. But i want to limit who has access to the Log Viewer in production.
So,i create a middleware
<?php
namespace App\Http\...
3
votes
1
answer
119
views
404 URLs does not pass through web Middlewares in Laravel 11, php8.2 and TwillCMS
I have a redirect middleware. This middleware checks if the path is defined in our Redirection module table.
Normally, when a page exists (200) say http://localhost/existing-page, I can redirect the ...
0
votes
1
answer
96
views
Unable to make my own 'api' middleware alias in order to use a dependency with laravel 11
So basically I work on a Laravel 11 project, and the session cookie is generated by a portal from which I access my application.
I have an AuthMiddleware aliased to 'sso' which is responsible for ...
2
votes
2
answers
333
views
How to change the default home path in Laravel 11?
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use ...
0
votes
1
answer
42
views
Middleware to have one user using its own database
I'm starting a SaaS and to avoid having a too big database, and to help for debugging, I would like each user to use its own database, without duplicating the laravel app.
I have been suggesting using ...
0
votes
1
answer
1k
views
laravel 11 Target class [role] does not exist ( spatie/laravel-permission)
i am developing REST API laravel 11 app i installed spatie/laravel-permission and i can create a user and assign role successfully also on login i can capture token and role successfully but when i to ...
1
vote
1
answer
79
views
I used Cache in Laravel to ban spaming IPs, searching for a better solution [closed]
This is how I do it:
$ip = $request->ip();
if (Cache::has('banned_ip_' . $ip)) {
return response()->json([
'message' => 'Access blocked',
'reason' => 'You have been ...
1
vote
1
answer
81
views
How to use multiple middleware to a laravel route group?
I'm trying to add a new middleware to a group of routes that I got in my routes/web.php
Route::group(['middleware'=>['xFrameOptionsHeader','VerifyHeaders']], function(){
Route::get('/', '...
1
vote
0
answers
74
views
Getting an error "Target class [admin] does not exist"
Basically I'm building a pet adoption site and now getting an error which says "Target class [admin] does not exist" when my admin user account is trying to approve 'adoption request' of any ...
1
vote
1
answer
84
views
How to access custom postman headers in laravel projects?
Laravel Project
I have created a custom Postman header called company_code, and it works on my local development environment on my PC.
However, when I deploy this project on a live server, the custom ...
0
votes
1
answer
194
views
Laravel Livewire 3 overwrites HTTP response headers
We have this middleware in my app because internal security asked us to overwrite these response headers.
class NoCacheControlHeaders
{
public function handle(Request $request, Closure $next)
{...
2
votes
1
answer
137
views
Laravel middlewares
I created a laravel middleware with this code:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Containers\...
1
vote
1
answer
90
views
This page isn't 't working127.0.0.1 redirected you too many times
I want to create middleware where when I want to access a website page I have to do a second login first, and if I don't have a token then the page will redirect to the login page. I entered the code ...
0
votes
0
answers
273
views
Authentication works in Laravel 11, but it returns null . Why?
In Laravel, I can sign up and log in without any issues using Breeze.
In my table, I have:
$table->enum('role', ['admin', 'user']);
Here’s how your bootstrap/app.php file looks:
<?php
use App\...
1
vote
1
answer
662
views
Laravel 11 - HasMiddleware's middleware() method conflits with Illuminate\Routing\Controller's middlware()
In my Controller that extends the Illuminate\Routing\Controller, i am trying to implement some middlware validations using the new HasMiddleware.
This is the code that i am trying to run:
<?php
...
1
vote
2
answers
2k
views
Laravel 11 Middleware route group api doesnt work
I have a api project with Laravel 11, and i want to make a middleware for admin api.
AdminMiddleware.php (custom middleware)
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\...
0
votes
1
answer
721
views
Using laravel 11 cookie to manually authenticate a request
im trying to authenticate a request sent from the front end from another domain
i tried to set the 'Cookie' header with the cookie value but it was blocked by the browser ,so i did the following
...
1
vote
1
answer
260
views
How to apply a different delay on different number of requests in laravel Rate Limit?
I am writing a rate limits middleware in which i have to do a folowing functionality
1:Sending first is instant the second request will ask you to wait 30 seconds, third will ask to wait 60 seconds, ...
1
vote
1
answer
576
views
Auth Middleware not working properly In Laravel 10
In my Laravel Project i have few routes which i want to protect if the user is not authenticated thats why i make this changes to Authenticate middleware :
namespace App\Http\Middleware;
use ...
0
votes
1
answer
120
views
Laravel 10: Session regeneration in middleware not updating values
I am working on a Laravel 10 application with middleware that checks if a token has expired. If it has, it generates a new token using refresh_token, creates a new session, and updates the session ...
-2
votes
1
answer
113
views
Laravel 11 Storage URL not triggering Middleware
I have a storage url that can be opened and it looks like this
<a href="{{ Storage::url('invoices/'. $invoice->invoice_number . '.pdf') }}?is_opened={{ $token }}" class="f-...
17
votes
4
answers
22k
views
Laravel 11 - Disable CSRF for a route
I have a route that serves as a webhook endpoint that gets called by a remote service, but the calls that the service makes to the webhook always fail.
After some inspection of the service logs, I ...
1
vote
0
answers
1k
views
CORS policy issue: 'Access-Control-Allow-Origin' header contains multiple values
I'm facing a CORS policy issue in my Laravel application when trying to make a request to an API endpoint from my frontend. The error message I'm receiving is:
Access to XMLHttpRequest at 'https://...
0
votes
1
answer
541
views
How to check if ConvertEmptyStringsToNull::class middleware is registered in Laravel 11
Through Laravel 10, I was able to check if the ConvertEmptyStringsToNull middleware was globally registered by using the following code:
$kernel = $this->getLaravel()->make('App\\Http\\Kernel');
...
0
votes
1
answer
494
views
Laravel 11 with MongoDB: Guards not working in Middleware
I tried using guards for admins but its not working in Middleware in Laravel 11. I have connected the MongoDB with Laravel 11 for managing its database.
My admin login function looks like below where ...
2
votes
0
answers
149
views
Laravel 8 session token lost after redirect to external URL
I have a Laravel 8 website in which users fill in a form and click a link to take them to an external payment website. Once the user has paid (or canceled payment), the payment website redirects the ...
-3
votes
1
answer
4k
views
How to return a 404 status and view from Laravel middleware [closed]
I'm building an admin section for a Laravel 10 app using the boilerplate Breeze routes and templates (for now) and I have a group of prefixed routes that I want to return a 404 error for in the ...
2
votes
2
answers
892
views
Adding custom data to middleware response in laravel 9 or 10 php
I want to implement a user tracking system, after searching I realized that I have to do this in the middleware. The problem I had was that I could only add values to the response header in the ...
0
votes
2
answers
77
views
Laravel JsonResource foreign table is empty
I'm a beginner with Laravel and inertia.
I use Laravel 10 with Inertia and react.
When I go to the index page, the field "$this->typeEducation->title" is filled, but when I click edit, ...
-1
votes
1
answer
106
views
laravel : how to by pass throttle middleware for some routes in
in my Laravel project
These two queries are executing everywhere regarding my route's middleware I need to skip them for some routes how can I do that
I have tried creating "withoutThrottle" ...
1
vote
1
answer
80
views
Repeating Middleware During Localization Check
Edit: Ali Ismaeel provided a great answer to my structure, but I had done a poor job of asking the question and re-wrote it. My edit history shows what he was addressing. Sorry, I'm trying to get ...
0
votes
1
answer
574
views
Target class [Spatie\Permission\Middleware\PermissionMiddleware] does not exist
How to fix Target class [Spatie\Permission\Middleware\PermissionMiddleware] does not exist.
I hope the code can run smoothly again, please help me, I've tried changing the code but it still doesn't ...
-1
votes
1
answer
485
views
Illuminate\Contracts\Container\BindingResolutionException Target class [admin] does not exist. (Laravel Version 7.30.6)
The error I face is
Illuminate\Contracts\Container\BindingResolutionException Target class [admin] does not exist. (Laravel Version 7.30.6)
My Routes are given below :
//admin routes
Route::group(['...
0
votes
2
answers
57
views
i am trying to use constructor in controller but failed !Why my constructor not working?
public function __construct()
{
if (Auth::check()){
if(Auth::user()->user_type == 'admin'){
return to_route('admin.dashboard');
} elseif(Auth::user()->user_type =...
0
votes
0
answers
185
views
Laravel API calls no longer work after upgrading to Laravel 8
I'm upgrading an old Laravel app to Laravel 8. Everything went fine with the upgrade except for being able to connect through the API. When I do try, I get a crash message Class 'Symfony\Bridge\...
0
votes
1
answer
1k
views
Handle exceptions and fatal errors into laravel middleware
I'm currently developing an API using Laravel 7.30.6 and I'd like to be able to handle all errors and return a Internal server error with HTTP code 500 on all the API routes if anything goes wrong, ...
0
votes
1
answer
353
views
Why does the auth middleware works half the time, with inertia / laravel
I've been trying to deploy a Laravel / Inertia app, using digitalOcean app Platform. In dev environment everythings goes well. In production, the middleware, auth and a custum one I made, works only ...
1
vote
1
answer
214
views
Middleware Not Functioning Only on API Routes in Laravel 9.19
I have set up a project and written some routes in the api.php route file. I created a middleware, registered the middleware in the Kernel.php file, and then implemented the middleware in the api.php ...
0
votes
1
answer
737
views
Laravel Middleware is returning null in authenticated user
I'm trying to prevent some users from accessing to some routes. I have created a middleware called CheckUserRole. But I always get a null response when I try to fetch any data from the logged-in user, ...
0
votes
1
answer
45
views
Setting Non-Empty Client Token in Laravel 8 Boot Method with Middleware
I am working with Laravel version 8, and I want to use the global scope to add a where clause to all queries of the User model.
/**
* The "booting" method of the model.
* @return void
*/
...
0
votes
1
answer
146
views
Laravel - Parameterized route full acces only for admin, but specific access to user logged
I'm buiding a user management system. The current routes on web.php are here:
Route::middleware(['admin'])
->prefix('users')
->name('users.')
->group(function() {
Route::...
0
votes
1
answer
107
views
Restrict the pages in laravel when using socialite as login
In laravel have added socialite login for google,but i wanted them to be authenticated first before going to /studentTable route. And if they are not authenticated then they go back to login.
Im new ...
2
votes
0
answers
190
views
How to create user access token for guest user to verify with AUTH:API middleware for API routes in Laravel
I want to verify bearer token for GUEST users in LARAVEL API so how can I generate user access token for guest users and also verify in AUTH:API middleware
0
votes
2
answers
984
views
Laravel : JWT Auth access auth()->user() return null
I am trying to use JWT for API authentication I am building, I have managed to get the JWT token with code like the following:
$user = User::select('id_user', DB::raw('AES_DECRYPT(id_user, "nur&...
1
vote
2
answers
2k
views
Laravel middleware logout
I want to make a middleware in my Laravel 9 project where if the user is inactive, they automatically get logged out. In my middleware class, like the following.
public function handle(Request $...
0
votes
1
answer
93
views
How to allow user to create a redirect from one URL to another URL
I am trying to allow a user (these would only be admin) to redirect one URL to another URL (I own all of these URLs so I am able to redirect them). I am currently passing the URLs they enter from the ...