laravel-routing

Laravel 4: Two different view pages for a single URI based on auth status

自古美人都是妖i 提交于 2019-12-07 08:21:47
问题 I have recently got into developing with Laravel 4 and I had a question about routes. For '/', I would like to have two different view pages based on the user's auth status. If a user is logged in and is viewing '/', I would like to show them a view with admin controls and when a user is viewing '/' as a regular user without logging in, I would like to offer a general information view. To accomplish this, I've been playing around with filter 'auth' and 'guest' but am having no luck. // app

Laravel 4 how check if a route only comes/redirected from another route?

亡梦爱人 提交于 2019-12-07 04:18:03
问题 Say i have localhost/public/admin that redirects immediately to localhost/public/user/login . How am I going to get the admin value in user/login ? 回答1: You'll need to grab the referer and check if it is contains 'admin'. Try the following $referer = Request::referer(); // or // $referer = Request::server('HTTP_REFERER'); if (strpos($referer,'admin') !== false) { dd('coming from admin') } Edit #1: As pointed out by @tomvo you can also use URL::previous() instead of Request::referer() in L4

Using Named URL in blade template

你离开我真会死。 提交于 2019-12-07 02:18:30
问题 In Django, I can do this: <a href="{% url 'account_login' %}">Account Link</a> which would give me domain/account/login where I have that URL named in my urls.py url(r'^account/login/$', views.Login.as_view(), name='account_login'), I want to do something similar in Laravel 5.2 I currently have something like this: Route::get('/survey/new', ['as' => 'new.survey', 'uses' => 'SurveyController@new_survey']); How do I use in my template, plus passing in parameters? I came across this: https:/

Is it possible to reorder or ignore parameters in controller routes?

£可爱£侵袭症+ 提交于 2019-12-06 16:00:22
The question title is the most explicit I could think of, but here's a use case/example for clarity's sake: Say I define the following route to show an article: Route::get('article/{slug}/{id}', 'ArticleController@show'); ... class ArticleController extends BaseController { public function show($id) { return View::make('article')->with('article', Article::find($id)); } } This won't work, as show will misake the $id parameter with the $slug parameter. Is there a way to pass only the $id parameter to the show method? I dont know if you still look for solution or not, but as I had the same

Laravel 5.2 - Every route redirects to the homepage

≡放荡痞女 提交于 2019-12-06 14:39:50
I just started an laravel 5.2 application. Every route I take (/register, /logout, login,...) redirects me to the homepage. Here are my routes <?php Route::group(['middleware' => ['web']], function () { //Register Route::get('/register', 'Auth\AuthController@getRegister'); Route::get('/register/success', 'Auth\AuthController@getRegisterSuccess'); Route::post('/register', 'Auth\AuthController@PostRegister'); //Login Route::get('/login', 'Auth\AuthController@getLogin'); Route::post('/login', 'Auth\AuthController@PostLogin'); //Password Reset Route::get('/password/reset/email', 'Auth

Laravel Custom Auth

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 11:56:21
Here i do the Login Validation $LoginData = Input::except(array('_token')) ; if(Auth::attempt($LoginData)) { return 'success'; } My Table is different so, here i change the table name in auth.php 'table' => 'administrators' But I have the dropdown to choose for the usertype. So how can i choose the tables for Authentication according to the usertypeinput. i.e., Table may be administrators or parents or employees I don't know whether Laravel supports the change of auth table name on fly or not. I can suggest you a quick solution. According to generalization theory of database design, you should

Intercept Laravel Routing

孤者浪人 提交于 2019-12-06 11:14:11
问题 I am busy building a Restful API in Laravel 5.1 where the API version is passed through the header. This way I can version the features rather than copy and pasting a whole route group and increment the version number. The problem I'm having is that I would like to have versioned methods, IE: public function store_v1 (){ } I have added a middleware on my routes where I capture the version from the header, but now need to modify the request to choose the correct method from the controller. app

Laravel 5 Password Reset with Angular View

*爱你&永不变心* 提交于 2019-12-06 11:09:28
I am trying to use the Laravel inbuilt password reset in my app where Laravel 5.1 acts as the backend api and Angular 1.3 for all front-end views. I have set-up the Password reset as per the docs where I have done the following: 1) Create the table php artisan migrate 2) Added this to the route: Route::post('password/email', 'Auth/PasswordController@postEmail'); Route::post('password/reset', 'Auth/PasswordController@postReset'); Since I will be using Angular to display frontend forms, I did not add the views for GET . I havent done any changes to the Auth/PasswordController.php and right now

Laravel/PHP - returning/redirecting from child class

寵の児 提交于 2019-12-06 07:44:34
This is my child controller: class VolunteersController extends \BaseController { public function index() { $this->checkForRoles(['admin']); //list some secret stuff for admin } } In my base controller I did this: class BaseController extends Controller { protected function checkForRoles($roles) { foreach ($roles as $role) { if (!(Auth::user()->hasRole($role))) { return Redirect::to('/'); } } } } Now what I expected was that the line return Redirect::to('/'); in BaseController would redirect the user to home page if his role is not admin. But it does not happen. //list some secret stuff for

Route using either a prefix or a domain

十年热恋 提交于 2019-12-06 04:47:27
问题 I am working on a platform that allows users to run their own site in either a sub folder of the main website domain, or map a custom domain for their site. When using a custom domain the URL structure for each route is slightly different in that it is prefixed with the username, but when using a custom domain then this prefix is not used. Is there a clever way to achieve this in my Route::group to handle both request types in one route and successfully use reverse routing to produce the