In my crudcontroller I have added
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
public function fetchTag()
{
return $this->fetch(\App\Tag::class);
}
But keep getting an error in console saying 405 Method not allowed for this POST route. I believe Backpack is to add the route automatically but the route is not found. Where/How do I add the route for a fetch (following the docs for inline-create)?
Related
When trying to hit the endpoint http://localhost:8080/users the page is getting "WhiteLabel Error". Can anyone resolve this issue. these are the snapshots of the controller class and error.
Your rest controller indicates that you have to access to “/courses”, but in the screenshot your are accessing to “/users”.
Change it to:
http://localhost:8080/courses
I'm writing some middleware in Laravel (version 8.0) which essentially checks for a deactivated organisation when an API route is called and it will log them out with the intention of redirecting to the sign in page with an appropriate message.
However, when the redirect runs it throws the following error:
The PUT method is not supported for this route. Supported methods: GET, HEAD.
The reason is because the API route being executed is a PUT method in this case so when it tries to run the redirect which expects a GET method it does not work.
Here is my middleware:
public function handle(Request $request, Closure $next): mixed
{
if (Auth::check() && Auth::user()) {
if($this->statusChecker::isServiceProviderDeactivated(Auth::user()['service_provider_id'])) {
auth()->guard('web')->logout();
(new SsoBroker())->logout();
return response()->redirectTo('/sign-in');
}
}
return $next($request);
}
The logout executes correctly (so if the user refreshes the page they are taken to the sign-in page) but the redirect does not work. I am not particularly experienced in writing middleware and I've done lots of research on this but not really finding any solutions. Since this site is a one-page react project the issue could lie there, but I am not sure. If anyone has any ideas I would appreciate it.
change the Route method instead of put to get/post
Route::get('/', [Auth::class, 'login'])
I've created the blog from blog tutorial, and I would to protect articles list, but I want that this be accesible across REST, I've activated json extensions.
All works well. I can add and retrieve list, but now I want to deny index and add from web and only be accesible from .json to public.
I tried with
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Auth->allow('index.json');
}
But this obviously doesn't work. All webpage is login protected as is in tutorial. Web services should be accesible to Android App (code is ready and working).
Thank you!
Of course that doesn't work, the allow() methods expects valid method names, and that's all the authentication component cares about, method/action names, it doesn't matter how the action was requested.
What you are trying to do requires you to check the type of the request, and based on the results, allow the actions. Checking the request type can be done using Request::is().
See Cookbook > Request & Response Objects > Checking Request Conditions
So it might be as simple as
if ($this->request->is('json')) {
$this->Auth->allow(['index', 'add']);
}
I am using symfony 1.4.
I need to redirect certain urls when 404 error occurs.
Let's say user is looking for a url http://example.com/oldurl and it doesn't exist I want to check if this url is set for redirect.
If url is set to be redirected I would like to redirect it to that url.
QUESTION: Which event should I hook into to get info about the requested url, that got redirected to 404 error page ?
P.S We only want to check for redirection if page doesn't exist. We do not want to run "the check" for every request, only when page not found!
thanks a lot!
Symfony fire an event each time a page is not found: controller.page_not_found.
You can find it in the documentation: http://www.symfony-project.org/reference/1_4/en/15-Events#chapter_15_sub_controller_page_not_found
Edit:
You can retrieve the url in the method that listen to this event by calling the context. With something like that:
$context = sfContext::hasInstance() ? sfContext::getInstance() : null;
if(null !== $context)
{
$requested_url = $context->getRequest()->getUri();
}
You can give a closer look to the plugin sfErrorNotifierPlugin, it catches exception and 404 error and send an email for a report. Look at how they handle 404 error.
I don't know where to hook exactly inside the execution stack, but I know the general cleaner way through routing. If you are doing routing without still having in code the default routing rule (which you shouldn't by practice since), then it would be as simple as the following in your app routing.yml (at the end):
catch_all:
url: /*
param: { module: yourModule, action: handleNotFound }
I need to know how to get the current module name in the bootstrap file of my zend application. On the load of the page I'm doing a request to a webservice to get the current user information by sending a hashed cookie and a token. The problem is that I only need to do this in two of my 3 modules so i need to be able to ask for example.
if ($moduleName !== "filteredmodule"){
// do the request
}
Thanks.
Bootstrap is for getting the application ready. I suggest you do this kind of call in a Controller Plugin (which you can use to get the current called module) or in the init() function of your controller.
This is how to get the current module via controller plugin:
<?php
final class YourApp_Controller_Plugin_YourPluginName extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$module = $request->getModuleName(); //This is the module
Docs: http://framework.zend.com/manual/en/zend.controller.plugins.html
One thing regarding Ashley's answer:
If you want to do
$module = $request->getModuleName();
as soon as possible, then do it in routeShutdown().
As the documentation states, "routeStartup() is called before Zend_Controller_Front calls on the router to evaluate the request against the registered routes. routeShutdown() is called after the router finishes routing the request."
So router dependant request parameters like module, controller, action or any other parameters specified in the route will be accessible in routeShutdown() and later functions.