laravel-routing

Named restful routes in Laravel 4

你。 提交于 2019-12-03 08:51:16
问题 So, I've been able to get restful controllers working with Route::controller('users','UserController'); class UserController extends BaseController { public function getAccount(){} } and so /users/account works. However if I try to do something like Route::any('account',array('as' => 'account','uses' => 'UserController@account')); and go to /account , it doesn't work ( NotFoundHTTPException ). Is there a way to use named routes and restful controllers in conjunction? I like how the restful

Restrict route access to non-admin users

纵然是瞬间 提交于 2019-12-03 07:48:25
问题 Goal I'm trying to create Admin route restriction for my log-in users. I've tried a check to see if my user is log-in , and also if the user type is Admin , and if they are, I want to allow them access to the admin route, otherwise, respond a 404. routes.php <!-- Route group --> $router->group(['middleware' => 'auth'], function() { <!-- No Restriction --> Route::get('dashboard','WelcomeController@index'); <!-- Admin Only --> if(Auth::check()){ if ( Auth::user()->type == "Admin" ){ //Report

Prevent Sessions For Routes in Laravel (Custom on-demand session handling)

纵然是瞬间 提交于 2019-12-03 05:58:25
I am building APIs for my Android app using laravel and default session driver set to REDIS. I found a good article here http://dor.ky/laravel-prevent-sessions-for-routes-via-a-filter/ which sort of serves the purpose. However when ever I hit the url it also hits the redis and generates the key which is empty. Now I want avoid creating empty session keys in redis. Ideally it should not hit the redis How can I do that? Can we customise sessios in a way so that sessions are generated only for specific routes (or disable for specific routes)? I can explain more with specific use case, please let

Laravel Route model binding with relationship

走远了吗. 提交于 2019-12-03 05:49:43
I am wondering if it is possible to return a relationship with laravels Route model binding ? Say is a have a user model with a relationship 'friends' to other users, and I want to return both the user info and the relationship from a route or controller. eg for the route domain.tld/user/123 Route::model('user', 'User'); Route::get('/user/{user}', function(User $user) { return Response::json($user); }); this will return me the user info fine but I also want the relationships, is there any easy/proper way to do this ? I know I can do this Route::get('/user/{user}', function((User $user) {

Named restful routes in Laravel 4

狂风中的少年 提交于 2019-12-02 21:27:32
So, I've been able to get restful controllers working with Route::controller('users','UserController'); class UserController extends BaseController { public function getAccount(){} } and so /users/account works. However if I try to do something like Route::any('account',array('as' => 'account','uses' => 'UserController@account')); and go to /account , it doesn't work ( NotFoundHTTPException ). Is there a way to use named routes and restful controllers in conjunction? I like how the restful system breaks up requests, and how named routes encapsulate the URI's and decouple them from the function

Restrict route access to non-admin users

不羁的心 提交于 2019-12-02 21:13:40
Goal I'm trying to create Admin route restriction for my log-in users. I've tried a check to see if my user is log-in , and also if the user type is Admin , and if they are, I want to allow them access to the admin route, otherwise, respond a 404. routes.php <!-- Route group --> $router->group(['middleware' => 'auth'], function() { <!-- No Restriction --> Route::get('dashboard','WelcomeController@index'); <!-- Admin Only --> if(Auth::check()){ if ( Auth::user()->type == "Admin" ){ //Report Route::get('report','ReportController@index'); Route::get('report/create', array('as'=>'report.create',

Laravel 5 making a route for a specific link

谁说我不能喝 提交于 2019-12-02 17:06:00
问题 I have a link that goes to a address like http://localhost/pages/vehicles?show=61 Is it possible to make a route for that kind of link i tired below route but it does not work Route::get('/pages/vehicles?show={id}', ['middleware' => ['roles'], 'uses' => 'PagesController@show', 'roles' => ['Admin']]); 回答1: I had a similar problem trying to send a form directly to a route (using something like /pages/vehicles/61) but it seems to be imposible (question here). If you don't have a specific route

Laravel Routing Conflict issue

人走茶凉 提交于 2019-12-02 16:29:18
问题 I have following url in laravel: 1.Need to change From: localhost/laravel/page/2/ to localhost/laravel/2/ My Route.php is Route::get('page/{id}/', array( 'as' => 'page', 'uses' =>'Frontcontroller@page')); But When I change to this, Route::get('/{id}/', array( 'as' => 'page', 'uses' =>'Frontcontroller@page')); I have noticed that it has conflict issues with other route ,Plz help me Thanx in advance 回答1: Just declare the new routes at the last of your all other routes and also add a where

Laravel 4 defining RESTful controllers

只谈情不闲聊 提交于 2019-12-02 16:22:27
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 verb we should like to use? For example: class PostController extends \BaseController { public function

Laravel 5 HTTP/Requests - pass url parameter to the rules() method

对着背影说爱祢 提交于 2019-12-02 08:28:35
问题 I'm trying to create a set of rules under the new \HTTP\Requests\UpdateArticle class for the slug field, which needs to have unique filter applied, but only when the id is not equal the url parameter of the route name article/{article} . What I got so far is: public function rules() { return [ 'title' => 'required|min:3', 'excerpt' => 'required', 'body' => 'required', 'slug' => 'required|unique:articles,slug,?', 'active' => 'required', 'published_at' => 'required|date' ]; } I need to replace