Category : laravel-routing

I’m building an API to support an external application. I have added several routes to it with no problem, but suddenly, when I add a new route (acars/delay), I get a 404 error when trying to hit http://myurl.dev/api/acars/delay with a POST request. Here is my api.php file: Route::post(‘acars/deactivate’, ‘[email protected]’); Route::post(‘acars/ofp’, ‘[email protected]’); Route::post(‘acars/create’, ‘[email protected]’); Route::post(‘acars/pirep’, ‘[email protected]’); ..

Read more

Considering this route in web.php: Route::middleware(‘auth:sanctum’)->get(‘/test’, [TestConnections::class, ‘test’]);, Sanctum rejects it if the token is invalid (it is the case if it expired, or a bad token is given, an empty one, etc.). When Sanctum rejects a route, Guard.php‘s __invoke method returns return; so Laravel tries to reach the route "login". Indeed, Laravel shows this ..

Read more

In web.php, I have set this route: Route::middleware(‘auth:sanctum,expiration:1’)->get(‘/test’, [TestConnections::class, ‘test’]);. The middleware Sanctum’s Guard.php (https://github.com/laravel/sanctum/blob/2.x/src/Guard.php) has indeed a constructor that accepts the expiration as a parameter. I’ve expected that setting this expiration in the route’s middleware declaration was possible but my var_dump($expiration) that I’ve set in the constructor returns NULL, not 1. So this way ..

Read more

I have a route group with this structure: Route::prefix(‘admin/{w_id}’)->middleware([‘auth’])->as(‘weblog.’)->group(function () { Route::get(‘/dashboard’, [HomePageController::class, ‘index’])->name(‘dashboard’); Route::resource(‘/blogcategory’, CategoryController::class); }); On dashboard route I have w_id in url and when I want to redirect user to blogcategory route (from anywhere) I need pass w_id manully in route helper class, I need some thing to set in globally from ..

Read more

For some reason the default route does not work (just "/admin") Route::prefix(‘admin’)->name(‘admin.’)->group(function () { Route::get(‘/’, ‘[email protected]’)->name(‘index’); //jcyjdyst yfcnhjryb cnhfybw Route::get(‘/main’, ‘[email protected]’)->name(‘main’); //jcyjdyst yfcnhjryb cnhfybw }); Route list: admin | admin.index | [email protected] | web | Sourc..

Read more

So in my service provider I bind the event model in the route: Route::model(‘event’, Event::class); Then I create this route: Route::view(‘/events/{event}/overview’, ‘cp.event-overview’) In this view I call a balde component that look like this: class EventHeader extends Component{ public $event; public function __construct(Event $event) { $this->event = $event; dd($event); } This returns an empty model ..

Read more

I have defined this route in the web.php route file: Route::get(‘/middleware_test_user_project_change/{pro_id}/{projet_id}’, function ($pro_id, $projet_id) { return ‘test’; })->middleware(‘user.project.change’); I have defined this handle function in my middleware (which I’ve added into the kernel with the following entry: ‘user.project.change’ => AppHttpMiddlewareCheckUserProposition::class): <?php namespace AppHttpMiddleware; use Closure; use IlluminateHttpRequest; use AppModelsUser; class CheckUserProposition { /** * Handle ..

Read more

I have created two apis one for college students and one for normal users. Normal users api is working fine but college api is not working properly. Can anyone help me fixing this error. What changes should I do ? Controller Codes for both are given below : Routes for both api Route::get(‘/get-user-enrollments/{offset?}’,’[email protected]’); Route::get(‘/get-college-enrollments/{offset?}’,’[email protected]’); Subject ..

Read more

I want to implement a dynamic way of the go-back button in my Laravel project. So I have this button: <a href="WHAT TO DO HERE"> <div class="go-back"> <div class="go-back-inside"> <h6 class="text">Go Back</h6> </div> </div> </a> Which I have included on every page, what I want to do is to have one button that is included ..

Read more

I’m working on a multi-language website where the URL’s contain localized strings. For instance: https://site/en/members/john-doe https://site/nl/leden/john-doe (and so for every language) In web.php I prefixed my routes. Via middleware I set the current language (retrieved from the first url-segment). This works fine for everything (both in controllers and in blade)… except for the urls generated ..

Read more

I’m getting this error: Expected status code 200 but received 404. Failed asserting that 200 is identical to 404. When I try to call it from my Unit Test: <?php namespace TestsUnit; use AppModelsProject; use TestsTestCase; class ExampleTest extends TestCase { public function testTakePlace() { $project = Project::factory()->make(); $response = $this->getJson(‘controllerUserProject_takePlace’, [ ‘project_id’ => $project->id, ..

Read more

I am using Laravel 6 and want to change the structure of some of my routes in the web.php file. When registering the following route like this: Route::view(‘/my-article’, ‘articles.my-article’)->name(‘my-article’); everything works as it should. But when changing the URL like this, adding /articles: Route::view(‘/articles/my-article’, ‘articles.my-article’)->name(‘my-article’); Suddenly no CSS is applied anymore. No Bootstrap, Fontawesome or ..

Read more

I am using Laravel 6 and want to change the structure of some of my routes. When registering the following route like this: Route::view(‘/my-article’, ‘articles.my-article’)->name(‘my-article’); everything works as it should. But when changing the URL like this, adding /articles: Route::view(‘/articles/my-article’, ‘articles.my-article’)->name(‘my-article’); Suddenly no CSS is applied anymore. No Bootstrap and no own stylesheet. JS script ..

Read more

I want to apply middleware on create route of resource controller but confused how to set middleware. Normally we can add middleware like this Route::get(‘api/users/{user}’, function (AppModelsUser $user) { return $user->email; })->middleware(‘name’); but when we have a resource controller so how could I apply middleware on single route of resource controller. Route::resource(‘front-pages’,’AdminFrontPagesController’); Sourc..

Read more

My route: Route::get(‘/{type?}/{filter?}’, [IndexController::class, ‘index’]); Is there a way, like form requests, where I can check that $type and $filter are specific values, for example $filter is equal to new or perhaps trending? I’ve considered just specifying the finite number of options as routes themselves: Route::get(‘/books/new’, [IndexController::class, ‘index’]); But I am then unable to get ..

Read more

I’m setting up a delete route in Laravel 8.6.0 like this: api.php Route::delete(‘code-rule/{id}’, ‘[email protected]’); CodeRuleController.php /** * Remove the specified resource from storage. * * @param AppModelsCodeRule $codeRule * @return IlluminateHttpResponse */ public function destroy($id) { return response()->json(CodeRule::where(‘id’, $id)->first()->destroy()); } Now when I try a delete request in postman to the url localhost:8080/api/v1/code-rule/13/ I get ..

Read more