Support the ongoing development of Laravel.io →
Configuration Requests
Last updated 1 year ago.
0

Route

Route::get('test', 'HomeController@tryMe');

Controller

<?php

class HomeController extends BaseController {
     
  public function tryMe()
  {
    echo 'test';
  } 

}

Last updated 1 year ago.
0

As far, as i know: this just routes me everytime to the tryMe-Method? What, if i want to call the 'testMe'-Method instead of 'tryMe'?

I do not want to implement a route just for every method i am implementing. Is there nothing like 'just route from the http-uri to the controller/action' ?

As it seems, i MUST set the 'get', 'post', 'put' etc. as a prefix to every method?

Last updated 1 year ago.
0

I think you need restfull controller :) Restful controller

Last updated 1 year ago.
0

Yes - i would like to use this restful-controller. The only thing i do not like is: I have to prefix my methods with 'get', 'post' or something like that. If there would be a way to implement just a 'testme()' and not a 'getTestme()' - THEN i would be happy :-)

Last updated 1 year ago.
0

Perhaps you could try a resource controller?

Last updated 1 year ago.
0

Use RESTful controllers.

Route::controller('home', 'HomeController');
Route::controller('city', 'CityController');

Done.

Use HTTP verbs. It'll help you. What are you going to do if you need a method that handles form submission? Are you going to create a method like formSubmit()? Then you have to add restrictions to allow only POST requests to that method. Why not let Laravel handle that for you automatically?

You can do better with something like getTryme() and postTryme() and submit the form to the same URL. When you review your code later, those method names tell you exactly what their roles are.

Having said that, this works:

Route::get('{resource}/{method}', function($resource, $method)
{
    $controllerName = ucfirst($resource).'Controller';
    $controller = new $controllerName;
    return $controller->{$method}();
});

I don't recommend it though.

Last updated 1 year ago.
0

Thanks. Yes, that's maybe not the best way to setup a routing.

But as it is for migrating an old, complex ZF1-Application it's okay. After we removed all of the old ZF1-Controller-Stuff, the next way could be to implement a new routing. At the moment it's just the simple way to move on to laravel.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

voodoo44 voodoo44 Joined 23 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.