laravel-routing

Laravel 4 defining RESTful controllers

狂风中的少年 提交于 2019-12-20 08:39:22
问题 So I'm new to the Laravel framework as of v4 and wondering what is the way to create and use RESTful controllers. Reading through the documentation, I'm a bit confused as to the difference between RESTful controllers and Resource controllers. When defining a RESTful controller, as per the docs, it suggests doing the following in routes.php : Route::controller('posts', 'PostController'); In the PostController , do we define the class methods by prefixing the name of the method with the HTTP

handle multiple post requests to same url Laravel 5

大憨熊 提交于 2019-12-20 04:51:55
问题 I have two forms on a page both submits the data via POST method . I want to handle both requests on the same url i.e /home and use different controllers and methods for both forms. Below are the two routes. Route::post('home' ,'FacebookControllers\PostsController@save'); Route::post('home' , 'FacebookControllers\MessageController@storeMessage'); In PostsController@save I am checking if(isset($_POST['submitPost']) && $_SERVER['REQUEST_METHOD']=='POST'){ //do something } and in

Laravel 5 : [Call to a member function getAction() on a non-object

限于喜欢 提交于 2019-12-20 03:10:12
问题 In my Controller, I have Route::getCurrentRoute()->getAction()['as'] Everything works well in the browser but as soon as I type php artisan route:list in the terminal I have this exception [Symfony\Component\Debug\Exception\FatalErrorException] Call to a member function getAction() on a non-object If I comment this line everything works well. 回答1: Seems obvious doesn't it? Get current route in a browser will return the currently visited route. In the terminal you do not have such a request.

Laravel case insensitive routes

谁说胖子不能爱 提交于 2019-12-19 07:16:12
问题 How do I define a case insensitive (part of a) route? Example: Route::get('/{userId}/profile'); http://domain.com/123/profile works fine. Any use of uppercase in the fixed part of the route does not work: http://domain.com/123/Profile does not work http://domain.com/123/proFILE does not work I understand how I can make parameters like {parameter} use a regex pattern using ->with(), but that does not help me with the fixed part of the route, like described above. 回答1: This can be solved by

How to pass query string params to routes in Laravel4

烂漫一生 提交于 2019-12-19 04:16:06
问题 I'm writing an api in Laravel 4. I'd like to pass query string parameters to my controllers. Specifically, I want to allow something like this: api/v1/account?fields=email,acct_type where the query params are passed along to the routed controller method which has a signature like this: public function index($cols) The route in routes.php looks like this: Route::get('account', 'AccountApiController@index'); I am manually specifying all my routes for clarity and flexibility (rather than using

Redirect www to non-www in Laravel with URL parameters

一笑奈何 提交于 2019-12-19 02:54:31
问题 How can I redirect URL from www.myapp.co to myapp.co ? And also if the URL has other parameter like www.myapp.co/other-parameter will be redirected to myapp.co/other-parameter where the other-parameter can be anything. Sorry for this noob question, I am still 1 week in using Laravel. BTW, I am using dynamic subdomain so I need only the redirect www to non-www and not the other subdomains. Route::group(array('domain' => 'myapp.co'), function() { Route::get('/', function() { return 'Hello!

Laravel form won't PATCH, only POST - nested RESTfull Controllers, MethodNotAllowedHttpException

天涯浪子 提交于 2019-12-19 02:26:12
问题 I am trying to allow users to edit their playlist . However, whenever I try to execute the PATCH request, I get the MethodNotAllowedHttpException error. (it is expecting a POST) I have set up RESTful Resource Controllers: Routes.php: Route::resource('users', 'UsersController'); Route::resource('users.playlists', 'PlaylistsController'); This should give me access to: (as displayed through php artisan routes ) URI | Name | Action PATCH users/{users}/playlists/{playlists} | users.playlists

laravel 5 custom 404

被刻印的时光 ゝ 提交于 2019-12-18 18:39:57
问题 This is driving me crazy. I'm working with Laravel 5 and it appears that the docs for 4.2 and generating 404 pages does not work. First, there is no global.php so I tried putting the following in routes.php: App::missing(function($exception) { return Response::view('errors.missing', array(), 404); }); This results in an error "method missing() not found" Debug is set to false. I've searched and searched but so far have found no information on setting 404 pages in Laravel 5. Would appreciate

TokenMismatchException in VerifyCsrfToken - Laravel 5.1

╄→гoц情女王★ 提交于 2019-12-18 16:32:22
问题 I am building a REST API using Laravel 5.1 and I am getting this error: TokenMismatchException in VerifyCsrfToken.php line 53: Here is my routes.php: Route::controller('city' , 'CityController' ); CityController: class CityController extends Controller { public function postLocalities() { $city = Input::get('cityName'); $response = $city; return $response; } } Here is the Stacktrace of the error when I hit the URL http://localhost:8000/city/localities?cityName=bangalore with POST method.

Laravel 5.4 - How to override route defined in a package?

强颜欢笑 提交于 2019-12-18 15:51:43
问题 I have created a package in Laravel 5.4 that sets up a basic backoffice. This package contains several routes that are using controllers from within the package. What I want to be able to do is to override the package defined routes in my application in order to plug custom controllers. For example, if I have a route Route::get('login', [ 'as' => 'admin.login', 'uses' => 'Auth\LoginController@showLoginForm' ]); defined in my package that will use the Vendor\Package\Controllers\Auth