Can you show the code of the middleware class (myscope:view-photos) ?
In middleware you usually call $next($request); passing the request to the next middleware or eventually; the controller.
It seems there's something going wrong there.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a route defined to return an array of image urls from my database. The route is defined in the api.php file as this:
Route::middleware(['auth:api'])->group(function () {
Route::middleware(['myscope:view-photos'])->get('/snapshots/photos','PhotoController@getPhotos');
});
In my PhotoController the function looks like this:
public function getPhotos(Request $request){
dd($request);
// $this->validate($request, [
// 'file_type_id'=>'required',
// 'photo_id'=>'required'
// ]);
$ret = File::where('photo_id',$request->photo_id)->get();
return $ret;
}
When I make that request with a logged in user I get an empty array "[]". The request parameters are not printed out.
I have other routes with the same scope and data is returned no problem. The controllers can do their work. However this particular request doesn't return anything from the controller.
So it must be something to do with authentication/middleware, however I am not sure. The reason I say this is because if I pull the route out of the scoped middleware group it returns as expected.
Any ideas?
Thanks in advance for any assistance.
Ok I have resolved the issue. No bugs to report.
What was happening is that I had a route with a wildcard above my /snapshots/photos route that was getting triggered before the actual route defined.
Therefore the wrong method in the controller was triggered.
Adding to this is that I had debug set to false in my .env file so I couldn't see any errors once I had in fact got the routing correct.
All in order now.
Thanks
Please or to participate in this conversation.