laravel-routing

Laravel: How to respond with custom 404 error depending on route

梦想的初衷 提交于 2019-11-30 03:53:50
I'm using Laravel4 framework and I came across this problem. I want to display a custom 404 error depending on requested url. For example: Route::get('site/{something}', function($something){ return View::make('site/error/404'); }); and Route::get('admin/{something}', function($something){ return View::make('admin/error/404'); }); The value of '$something' is not important. Shown example only works with one segment, i.e. 'site/foo' or 'admin/foo' . If someone request 'site/foo/bar' or 'admin/foo/bar' laravel will throw default 404 error. App::missing(function($exception){ return '404: Page Not

How to route GET and POST for same pattern in Laravel?

对着背影说爱祢 提交于 2019-11-30 02:46:40
Does anyone know of any way in Laravel 4 which combines these 2 lines into one? Route::get('login', 'AuthController@getLogin'); Route::post('login', 'AuthController@postLogin'); So instead of having to write both you only have to write one since their both using the 'same' method but also the URL remains as site.com/login instead of a redirect to site.com/auth/login ? I'm curious since I remember CI has something like that where the URL remains the same and the controller is never shown: $route['(method1|method2)'] = 'controller/$1'; You could try the following: Route::controller('login',

Set session variable in laravel

南笙酒味 提交于 2019-11-30 01:58:37
I would like to set a variable in the session using laravel this way Session::set('variableName')=$value; but the problem is that I don't know where to put this code, 'cause I would like to set it for one time (when the guest visite the home page or any other page)? The main idea is to use a global variable to use it in all application controllers, I heared about something related to configuration variables but I'm not sure if it will be a good Idea to use config variables or only the session? Thanks The correct syntax for this is... Session::set('variableName', $value); To get the variable,

Can I group multiple domains in a routing group in Laravel?

a 夏天 提交于 2019-11-30 00:05:06
Let's say I have the following: Route::group(array('domain' => array('admin.example.com')), function() { ... }); Route::group(array('domain' => array('app.example.com')), function() { ... }); Route::group(array('domain' => array('dev.app.example.com')), function() { ... }); Is there any way to have multiple domains share a routing group? Something like: Route::group(array('domain' => array('dev.app.example.com','app.example.com')), function() { ... }); Laravel does not seem to support this. I'm not sure why I didn't think of this sooner, but I guess one solution would be to just declare the

Laravel 5 Resourceful Routes Plus Middleware

笑着哭i 提交于 2019-11-29 21:14:22
Is it possible to add middleware to all or some items of a resourceful route? For example... <?php Route::resource('quotes', 'QuotesController'); Furthermore, if possible, I wanted to make all routes aside from index and show use the auth middleware. Or would this be something that needs to be done within the controller? In QuotesController constructor you can then use: $this->middleware('auth', ['except' => ['index','show']]); Reference: Controller middleware in Laravel 5 You could use Route Group coupled with Middleware concept: http://laravel.com/docs/master/routing Route::group([

My Routes are Returning a 404, How can I Fix Them?

北城余情 提交于 2019-11-29 20:32:37
I've just started learning the Laravel framework and I'm having an issue with routing. The only route that's working is the default home route that's attached to Laravel out of the box. I'm using WAMP on Windows and it uses PHP 5.4.3, and Apache 2.2.22, and I also have mod_rewrite enabled, and have removed the 'index.php' from the application.php config file to leave an empty string. I've created a new controller called User : class User_Controller extends Base_Controller { public $restful = true; public function get_index() { return View::make('user.index'); } } I've created a view file in

How to structure a modular app in Laravel 5?

主宰稳场 提交于 2019-11-29 18:41:37
I would like to divide my application in modules. For instance, there would be a "core" modules that contains the basic login functionality, app layout/formatting (CSS etc), user management and a diary. Later on I may create other modules like a contact manager that can easily be added or removed from the application. There would be some logic in the apps navigation for determining which modules are present and to show/hide the links to them. How can I do this in terms of directory structure, namespaces and anything else that's needed? I am looking at creolab/laravel-modules but it states that

order of route declarations in laravel package

 ̄綄美尐妖づ 提交于 2019-11-29 15:30:30
I have made a laravel package which contains a route, it is a special route that catches a large number of possible urls. I don't want my route to take precedence over other packages or routes declared in the main application. How can I ensure that my route is the last route declared? Routes are evaluated in the order that they are listed in routes.php. Simply making sure this route is the last one in the array should do it. update I believe you could just register the route in the App::before filter, which would register it after all user routes. 来源: https://stackoverflow.com/questions

Method not allowed when PUT used over AJAX for Laravel resource

前提是你 提交于 2019-11-29 13:47:05
I've got this resource in routes.php: Route::resource('items', 'ItemsController', ['before' => 'admin_access']); Trying to reach ItemsContoller@update method through AJAX but it's kicking out a 405 Method not allowed error: var $inputs = $('input', row); var id = $(row).find('.edit').data('id'); var data = $inputs.serializeJSON(); data['_token'] = $('input[name=_token]').val(); data['_method'] = 'PUT'; console.debug(data); $.ajax({ url: 'items/' + id, method: 'PUT', dataType: 'json', data: data, complete: function (data) { if (data.success) { itemsTable.ajax.reload(); } } }); Both the id and

Laravel 5 custom validation redirection

家住魔仙堡 提交于 2019-11-29 09:17:26
问题 I have a website which consist of 2 different login form at 2 places, one on the navbar and the other one is a login page which will be used when the system catches an unlogged visitor. Can I ask what have I done wrong in my LoginRequest.php where I've set a condition to redirect to a custom login page if there is any sort of error in the login process? I have my codes as below: <?php namespace App\Http\Requests; use App\Http\Requests\Request; class LoginRequest extends Request { /** *