How to get guarded_name of route I get from getRoutes method on Laravel - laravel

I want to get guarded_name of route I get from getRoutes() method on Laravel.
I can get route name by getName() method. But how to get wether the route is guarded for web or api of that route name?

I found answer from group discussion.
$route->getAction('middleware')
Thank you for your responses.

If you want to know the middleware applied on the route
Route::current()->computedMiddleware;

Related

Get Controller name and Method in laravel

I have to get my controller and method name from route, for example:
Route::get('/', 'HomeController#index')->name('home');
I have to get:
HomeController#index
Also, I have to get name of the action of my route(like POST and GET) automatically from my controller as well.
EDIT:
https://www.nicesnippets.com/blog/how-to-get-current-route-name-path-and-action-in-laravel-6
Thanks to this website, now I can get the method and controller from routes, the remaining thing that I still dont found is to how to get the action(ex:POST or GET) from my route
Does anyone have any suggestions?
You are looking for request()->route()->getActionName();

Laravel API routes - Same path, multiple methods

I want to make manually, some endpoints for a customer model.
I have these routes :
Route::get('customer/', 'CustomerRestController#all')->name('api_customer_all');
Route::get('customer/{id}', 'CustomerRestController#get')->name('api_customer_get');
Route::post('customer/', 'CustomerRestController#addOrUpdate')->name('api_customer_post');
Route::delete('customer/{id}', 'CustomerRestController#delete')->name('api_customer_delete');
If I call the post route with postman, the GET response is return !
Do you know why please ?
Thanks,

LARAVEL - INPUT ERROR - The POST method is not supported for this route. Supported methods: GET, HEAD

I'm trying to create an input form but couldn't find the solution from the error
This is what it said
My View Code
My Controller
My Router
I've tried some tips online but it still won't work
It's because your route name is not defined. you should add the route name like this
Route::post('CreateItem', 'CreateItem#insert')->name('CreateItem');
I think is related to the route name. Have you check which uri is posting the form? Can you try:
Route::post('/createItem', function () {
//
})->name('createItem');
Sorry, got the answer
Route::post('CreateItem','CreateItem#insert');
to
Route::post('/create_item','CreateItem#insert');
and
class CreateItem extends Controller
in my question, I typed the wrong controller name, it should be CreateItem
Thanks for the effort to answer my question tho..

laravel api route is not redirecting?

I am new to laravel,I had wrote api route code to register controller:
Route::post('test','Api\Auth\RegisterController#index');
In Register controller i had written simple code
public function index(Request $request)
{
return 'hello';
}
I am getting the output in postman like:
Sorry, the page you are looking for could not be found.
not hello.
Here the images:
1 3
Routes defined in the routes/api.php file are nested within a route
group by the RouteServiceProvider. Within this group, the /api URI
prefix is automatically applied so you do not need to manually apply
it to every route in the file.
You are trying to make a request to a route which does not exist.
In Postman
Change:
http://localhost:8080/App/api/test
To:
http://localhost:8080/api/test
You're telling laravel to route assoaciate '/api/test', not '/App/api/test', which is the adress you're trying to reach.
Also, if you plan to reach that address straight from the location bar of your browser, you should register the 'GET' method as well.
As you are returning something in function you need to use route as get() instead of post().
Route::get('test','Api\Auth\RegisterController#index');

Method name as Route - codeigniter

How can I do the following in routes dynamically?
$route['notifications'] = 'admin/notifications';
$route['categories'] = 'admin/categories';
This means that any method name under my controller is the landing page.
I don't want the admin controller to appear in the url.
I would simply use $CI->router->method in routes by I can't use get_instance in routes config.
What do I have to do?
Thanks!
It's difficult to get dynamic routes since at that point there's not much of CodeIgniter loaded.
I use the following to move all the methods of a controller to the first segment:
$route['(?!(api|account|more))(\w+)/(.*?)'] = "admin/$2/$3";
$route['(?!(api|account|more))(\w+)'] = "admin/$2";
Where api|account|more are routes being ignored.

Resources