I have just put a practice laravel app on my development server at app.mydomain.co
I have looked at the docs and I wrapped the routes with the sub domain group like so
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::group(array('domain' => 'app.mydomain.co'), function()
{
Route::get('/', array('as'=>'home', 'uses'=>'QuestionController#getIndex'));
//Route::get('create', array('as'=>'create', 'uses'=>'UserController#getCreate'));
//Route::get('login', array('as'=>'login', 'uses'=>'UserController#getLogin'));
/*
Define RESTful Controllers
*/
Route::controller('user', 'UserController');
Route::controller('questions', 'QuestionController');
});
The home page works fine but the rest of the routes are 404 not found errors so obviously I am doing something wrong, any ideas?
here is the output for php artisan routes with the domain substituted with app
+--------------+--------------------------------------------------------+------+-------------------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------------+--------------------------------------------------------+------+-------------------------------------+----------------+---------------+
| qapp.app.co | GET /user/index/{v1}/{v2}/{v3}/{v4}/{v5} | | UserController#getIndex | | |
| qapp.app.co | GET /user | | UserController#getIndex | | |
| qapp.app.co | GET /user/create/{v1}/{v2}/{v3}/{v4}/{v5} | | UserController#getCreate | | |
| qapp.app.co | POST /user/store/{v1}/{v2}/{v3}/{v4}/{v5} | | UserController#postStore | | |
| qapp.app.co | GET /user/login/{v1}/{v2}/{v3}/{v4}/{v5} | | UserController#getLogin | | |
| qapp.app.co | POST /user/login/{v1}/{v2}/{v3}/{v4}/{v5} | | UserController#postLogin | | |
| qapp.app.co | GET /user/logout/{v1}/{v2}/{v3}/{v4}/{v5} | | UserController#getLogout | | |
| qapp.app.co | GET /user/{_missing} | | UserController#missingMethod | | |
| qapp.app.co | GET /questions/index/{v1}/{v2}/{v3}/{v4}/{v5} | | QuestionController#getIndex | | |
| qapp.app.co | GET /questions | | QuestionController#getIndex | | |
| qapp.app.co | POST /questions/store/{v1}/{v2}/{v3}/{v4}/{v5} | | QuestionController#postStore | | |
| qapp.app.co | GET /questions/show/{v1}/{v2}/{v3}/{v4}/{v5} | | QuestionController#getShow | | |
| qapp.app.co | GET /questions/edit/{v1}/{v2}/{v3}/{v4}/{v5} | | QuestionController#getEdit | | |
| qapp.app.co | PUT /questions/update/{v1}/{v2}/{v3}/{v4}/{v5} | | QuestionController#putUpdate | | |
| qapp.app.co | GET /questions/your-questions/{v1}/{v2}/{v3}/{v4}/{v5} | | QuestionController#getYourQuestions | | |
| qapp.app.co | GET /questions/{_missing} | | QuestionController#missingMethod | | |
| | GET / | home | QuestionController#getIndex
When I look at the apache error log it appears to be looking in the laravel public folder for a file or directory related to the php query so if I am trying to access the questions controller method show with url qapp.app.co/questions/show/14 the error is file does not exist: /var/www/app/public/questions
I was able to solve my problem by setting AllowOverride to All in the virtual host. Maybe it will work for you too? See http://laracasts.com/forum/351-how-do-you-install-laravel-into-a-subdomain
The home page works fine but the rest of the routes are not found errors so obviously I am doing something wrong
This would already give you a hint what's actually wrong with your config. The route would prioritize from top to bottom, so technically you should define '/' route at the bottom (and not the top.
Related
this is the first time that I try to migrate a Laravel application from my local environment to my remote server.
So basically I have uploaded the entire content of my local Laravel 5.4 application into this folder of my remote server:
/var/www/html/HotelRegistration
Then I am trying to opening this URL into the browser (my remote server):
http://89.36.211.48/HotelRegistration/public/
and how you can see the standard Laravel homepage appear (it is expected, I yet have to replace this page with a custom one).
The problem is that in my web.xml file I have declared these routes:
Route::get('/', function () {
return view('welcome');
});
Route::get('contact', function() {
return View::make('contact');
});
Route::post('contact', 'EnquiryController#index');
Route::resource('/registration', 'RegistrationController');
The first one is the one related to the standard Laravel page that works fine, the last one is:
Route::resource('/registration', 'RegistrationController');
and it should handle HTTP GET request toward the /registration by the RegistrationController class, this controller class contains this index() method:
/**
* Metodo che mostra la pagina di registrazione di un nuovo utente albergatore.
* #return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(){
Log::info('index() START');
return view('/registration/index');
}
that opening this URL:
http://89.36.211.48/HotelRegistration/public/registration
should show a registration page. But, as you can see opening it I obtain a Not Found error message.
Into the /var/www/html/HotelRegistration/storage/logs/laravel.log file there is nothing, I expected the output of the log putted at the beginning of the previous method controller, so it seems that it doesn't not enter in this method.
The strange thing is that opening the same URL on my localhost system (http://localhost/HotelRegistration/public/registration) it works fine.
I am thinking that maybe it could be a routes problem (maybe some route is missing), if I perform this statment on my local environment:
php artisan route:list
I obtain:
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | activate | | App\Http\Controllers\RegistrationController#activate | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | contact | | Closure | web |
| | POST | contact | | App\Http\Controllers\EnquiryController#index | web |
| | GET|HEAD | errors | errors | Closure | web |
| | POST | registration | registration.store | App\Http\Controllers\RegistrationController#store | web |
| | GET|HEAD | registration | registration.index | App\Http\Controllers\RegistrationController#index | web |
| | GET|HEAD | registration/create | registration.create | App\Http\Controllers\RegistrationController#create | web |
| | DELETE | registration/{registration} | registration.destroy | App\Http\Controllers\RegistrationController#destroy | web |
| | PUT|PATCH | registration/{registration} | registration.update | App\Http\Controllers\RegistrationController#update | web |
| | GET|HEAD | registration/{registration} | registration.show | App\Http\Controllers\RegistrationController#show | web |
| | GET|HEAD | registration/{registration}/edit | registration.edit | App\Http\Controllers\RegistrationController#edit | web |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
that contains this route:
| | GET|HEAD | registration | registration.index | App\Http\Controllers\RegistrationController#index | web |
that should be the route related to the previous index() method of my controller.
But I can found it also performing the same statment on my remote environment:
root#Betrivius-VPS:/var/www/html/HotelRegistration# php artisan route:list
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | activate | | App\Http\Controllers\RegistrationController#activate | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | contact | | Closure | web |
| | POST | contact | | App\Http\Controllers\EnquiryController#index | web |
| | GET|HEAD | errors | errors | Closure | web |
| | GET|HEAD | registration | registration.index | App\Http\Controllers\RegistrationController#index | web |
| | POST | registration | registration.store | App\Http\Controllers\RegistrationController#store | web |
| | GET|HEAD | registration/create | registration.create | App\Http\Controllers\RegistrationController#create | web |
| | GET|HEAD | registration/{registration} | registration.show | App\Http\Controllers\RegistrationController#show | web |
| | PUT|PATCH | registration/{registration} | registration.update | App\Http\Controllers\RegistrationController#update | web |
| | DELETE | registration/{registration} | registration.destroy | App\Http\Controllers\RegistrationController#destroy | web |
| | GET|HEAD | registration/{registration}/edit | registration.edit | App\Http\Controllers\RegistrationController#edit | web |
+--------+-----------+----------------------------------+----------------------+------------------------------------------------------+--------------+
So what could be the problem? Why on my remote environment this URL (http://89.36.211.48/HotelRegistration/public/registration) seems not to be hanbdled as done in the local one?
What could be the problem? What am I missing? How can I try to fix it?
You need to first change the permissions and give the requires permission and run this command
composer install
or
composer update
Thank you
When using RESTful resource controllers, we can use route::resource() to work with, but the URIs seem to be default.
+--------+-----------+--------------------+---------------+---------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+--------------------+---------------+---------------------------------------------+------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | items | items.index | App\Http\Controllers\ItemController#index | web |
| | POST | items | items.store | App\Http\Controllers\ItemController#store | web |
| | GET|HEAD | items/create | items.create | App\Http\Controllers\ItemController#create | web |
| | GET|HEAD | items/{items} | items.show | App\Http\Controllers\ItemController#show | web |
| | PUT|PATCH | items/{items} | items.update | App\Http\Controllers\ItemController#update | web |
| | DELETE | items/{items} | items.destroy | App\Http\Controllers\ItemController#destroy | web |
| | GET|HEAD | items/{items}/edit | items.edit | App\Http\Controllers\ItemController#edit | web |
| | POST | register | signup | App\Http\Controllers\UserController#SignUp | web |
| | GET|HEAD | signup | | Closure | web |
+--------+-----------+--------------------+---------------+---------------------------------------------+------------+
(ignore the first and the last two, we're looking at the 'items.something' routes)
I want to, for example, change "items/create" to "items/new".
On a previous question, the answer was "No", but since the question is over one year old and Laravel developments seems to be pretty fast, is there already a solution?
The answer hasn't really changed. You can't customize a resource controller action directly. There is a workaround however: you can exclude it and add it yourself.
First make your resource route partial and exclude the action(s) you don't want:
https://laravel.com/docs/5.2/controllers#restful-partial-resource-routes
Route::resource('items', 'ItemController', ['except' => [
'create'
]]);
Then you can add your own routes in addition:
https://laravel.com/docs/5.2/controllers#restful-supplementing-resource-controllers
Route::get('items/new', 'ItemController#new');
Make sure to stick that before the resource route, as mentioned in the docs.
Note you can customize the route name, as mentioned in that previous thread you linked to.
I created a controller named CatController with php artisan make:controller CatController. So it generated the next route list:*-> What generated the route list is on routes.php Route::resource('cat','CatsController');
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------+-------------+-------------------------------------------------+------------+
| | GET|HEAD | / | | Furbook\Http\Controllers\CatController#index | |
| | GET|HEAD | cat | cat.index | Furbook\Http\Controllers\CatController#index | |
| | POST | cat | cat.store | Furbook\Http\Controllers\CatController#store | |
| | GET|HEAD | cat/create | cat.create | Furbook\Http\Controllers\CatController#create | |
| | DELETE | cat/{cat} | cat.destroy | Furbook\Http\Controllers\CatController#destroy | |
| | PATCH | cat/{cat} | | Furbook\Http\Controllers\CatController#update | |
| | PUT | cat/{cat} | cat.update | Furbook\Http\Controllers\CatController#update | |
| | GET|HEAD | cat/{cat} | cat.show | Furbook\Http\Controllers\CatController#show | |
| | GET|HEAD | cat/{cat}/edit | cat.edit | Furbook\Http\Controllers\CatController#edit | |
Later on I thought it would be better to call it CatsController and handle the urls as cats/... so I renamed the controller but I still have the same default REST actions URIs.
Is there anyway to change it? How should I proceed?
To my knowledge the make:controller command only generates the controller file, not any route definitions. The routes defined there look like they've beed generated by a Route::resource definition that would look like this:
Route::resource('cat', 'CatController');
To make that work with cats and CatsControllers you should change it to this:
Route::resource('cats', 'CatsController');
You can read more on RESTful Resource Controllers in the Laravel Documentation.
I'm using Laravel Resource routing (through a controller). Here is the routing code
Route::resource( 'difficulty', 'DifficultyController', [ 'only' => [ 'index', 'show', 'update', 'create' ] ] );
Here are the routes created
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
| | GET|HEAD | difficulty | difficulty.index | App\Http\Controllers\DifficultyController#index | |
| | GET|HEAD | difficulty/create | difficulty.create | App\Http\Controllers\DifficultyController#create | |
| | PATCH | difficulty/{difficulty} | | App\Http\Controllers\DifficultyController#update | |
| | GET|HEAD | difficulty/{difficulty} | difficulty.show | App\Http\Controllers\DifficultyController#show | |
| | PUT | difficulty/{difficulty} | difficulty.update | App\Http\Controllers\DifficultyController#update | |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
It works fine, except that I don't need the "HEAD" and "PATCH" methods and I want to remove them. So listing routes will display the following
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
| | GET | difficulty | difficulty.index | App\Http\Controllers\DifficultyController#index | |
| | GET | difficulty/create | difficulty.create | App\Http\Controllers\DifficultyController#create | |
| | GET | difficulty/{difficulty} | difficulty.show | App\Http\Controllers\DifficultyController#show | |
| | PUT | difficulty/{difficulty} | difficulty.update | App\Http\Controllers\DifficultyController#update | |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
Is it possible to do it? I'm using Laravel 5.1
What about just doing explicit declarations?
Route::get('/difficulty','DifficultyController#index');
Route::get('/difficulty/create','DifficultyController#create');
Route::get('/difficulty/{difficulty}','DifficultyController#show');
Route::put('/difficulty/{difficulty}','DifficultyController#update');
I even prefer having it this way since it gives a clearer picture of what your application does.
I have the following Route defined:
Route::resource('profile', 'ProfileController', ['except' => ['create', 'destroy']]);
However, when I try and redirect to the profile/{id} method using the following:
redirect()->route('profile', [$userId]);
I get the following error:
InvalidArgumentException in UrlGenerator.php line 278:
Route [profile] not defined.
What could be the issue?
The route method takes a route name as the first argument. All specific resource routes will get their own names, however there's none created with the name of the base resource (profile).
By running php artisan route:list you will see a list of all routes along with their names. For you it should look something like this:
+--------+----------+-----------------------------------------+-----------------+---------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------+-----------------+---------------------------------------------------+------------+
| | POST | profile | profile.store | App\Http\Controllers\ProfileController#store | |
| | GET|HEAD | profile | profile.index | App\Http\Controllers\ProfileController#index | |
| | GET|HEAD | profile/create | profile.create | App\Http\Controllers\ProfileController#create | |
| | PATCH | profile/{profile} | | App\Http\Controllers\ProfileController#update | |
| | PUT | profile/{profile} | profile.update | App\Http\Controllers\ProfileController#update | |
| | DELETE | profile/{profile} | profile.destroy | App\Http\Controllers\ProfileController#destroy | |
| | GET|HEAD | profile/{profile} | profile.show | App\Http\Controllers\ProfileController#show | |
| | GET|HEAD | profile/{profile}/edit | profile.edit | App\Http\Controllers\ProfileController#edit | |
+--------+----------+-----------------------------------------+-----------------+---------------------------------------------------+------------+
So since it seems you are intending to show a user profile, this should be what you are looking to do:
redirect()->route('profile.show', [$userId]);
Try redirect this way
return redirect('profile/2');