laravel-routing

Pass fixed variable from route to controller in Laravel

早过忘川 提交于 2019-12-06 04:12:06
I'm trying to pass a variable through my route to my controller, but I have multiple routes (categories) leading to the same controller i.e. Route::get('/category1/{region}/{suburb?}', 'SearchController@search'); Route::get('/category2/{region}/{suburb?}', 'SearchController@search'); Making /category1, 2, etc. to be a parameter /{category} is not an option and I don't want to make separate controller function for each category. How do I send the first segment of the url to my search controller? i.e. category1 or category2? At present controller is as follows: public function search($region,

Should I Nest Routes to Resources in Laravel?

安稳与你 提交于 2019-12-06 01:24:16
问题 This may be a little subjective, but I feel that best-practice must exist (or even good design when it comes to Laravel apps). Googling results in lots of things that are not to do with the actual points in this question. Say I am building a web application that has teams, which may have projects, which may have documents. Should I design the routing so that documents are within the path of the projects they belong to, which are then within the path of the teams they belong to, or keep things

How can I delete a post resource in laravel 5?

淺唱寂寞╮ 提交于 2019-12-05 13:45:41
Laravel 5 version I am working on a project with the new laravel 5 release and for some reason i cannot delete a post, when I press delete it just redirects me to the post show page with the id such as /post/3 and I get a blank white page, when I go back to index view I get all the posts and that one has not been deleted. Here is what I have below: Posts migration file use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; class CreatePostsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('posts',

Vue router server configuration for history mode on nginx does not work

最后都变了- 提交于 2019-12-05 12:00:58
I read the following note from vue router documentation Note : when using the history mode, the server needs to be properly configured so that a user directly visiting a deep link on your site doesn't get a 404. So, I try to configure my nginx like the following server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/laravel/public/; index index.php index.html index.htm; server_name working.dev; location /user { rewrite ^(.+)$ /index.php last; } location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri /index.php =404;

Add url extensions to Laravel routes

前提是你 提交于 2019-12-05 09:33:36
Is it possible to add an extension to laravel routes like so? http://www.mywebsite.com/members/login.html and another page with a different extension http://www.mywebsite.com/contactus.htm I am transitioning an old website into laravel but the owner doesn't want to change the URL for SEO purposes. Yes, this is certainly possible and very straightforward to do with Laravel. routes.php: Route::get('members/login.html', function() { return View::make('members.login'); } ); Then you need to create the view members/login.php or members/login.blade.php in your views directory. Route::get('{id}-

How to build a Laravel route that requires a specific URL query parameter?

允我心安 提交于 2019-12-05 09:27:46
Let's say I have URLs like this: localhost/ admin/users/ <--- Main Admin Users page localhost/ admin/users/?data=refresh <---- A typical ajax request made from that page And a simple controller like this: class UsersController extends Controller { public function index() // call some services // return a view } public function dataRefresh { // call some services // return some JSON } } And here's my routes.php I'm working on: Route::get('admin/users', array('as' => 'admin.users', 'uses' => 'Admin\Users\UsersController@index')); Route::get('admin/users????' , array('before' => 'ajax', 'as' =>

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

你离开我真会死。 提交于 2019-12-05 08:27:15
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 ? 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 Edit #2: It's actually mispelled as referer instead of referrer as point out by @JamesF Edit #3: In Laravel 5

Temporarily disable / bypass Middleware

大憨熊 提交于 2019-12-05 08:02:21
In my Application I implemented a OAuth2-Server ( oauth2-server-laravel ) in combination with a custom Authentication Package ( Sentinel by Cartalyst ). In my routes.php: Route::group(['before' => 'oauth'], function() { // ... some routes here } So the request must provide an authorization header or the application quits with an OAuthException. Now I want to unittest my controllers. So I have to seed my database with a OAuth session and access token for every test. Then overwrite the call() -method of TestCase and set the HTTP-Authorization Header with the Bearer Token. Is there a way to

Using Named URL in blade template

流过昼夜 提交于 2019-12-05 06:16:47
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://laravel.com/docs/5.1/helpers , but it was just a piece of a white page without relevant content of how to

Laravel 5 - NotFoundHttpException in RouteCollection.php line 143

末鹿安然 提交于 2019-12-05 04:23:58
I get this error: Sorry, the page you are looking for could not be found. 1/1 NotFoundHttpException in RouteCollection.php line 143: in RouteCollection.php line 143 at RouteCollection->match(object(Request)) in Router.php line 746 at Router->findRoute(object(Request)) in Router.php line 655 at Router->dispatchToRoute(object(Request)) in Router.php line 631 at Router->dispatch(object(Request)) in Kernel.php line 229 at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline\