I'm new to laravel and have just created a project(laravel version 5.4.34).
After using:
composer create-project Laravel/Laravel project
and after adding the details for a mysql database connection and running
php artisan make:auth
I browse to the url of the project and get the basic laravel homepage, with the login and register links in the top left.
When i click either the register or the login link, it seems to get stuck in a redirect loop. How would this happen just after installation - would this be a routing problem?
UPDATE after Taylor Foster's comment
app/Http/Controllers/Auth/LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
routes/web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
I think those are the locations of files. Do I need to add routes for /login and /register myself?
I'm not sure if this is useful, though I have been watching the second beginner laracast and follow instructions on making a new route, and that URL doesn't work either, I add:
Route::get('/about', function () {
return view('about');
});
to the routes/web.php
and create a basic page showing a h1 tag saying About, and save it at resources/views/about.blade.php as instructed.
This could be the same issue with the auth problem? I don't get why a standard installation of laravel's routes would simply not work - and ideas/advice would be greatly appreciated.
In case anyone had the same problem as I did when starting out with Laravel, adding:
<Directory "/var/www/project/public">
AllowOverride all
</Directory>
within the virtualhost config seems to have solved the problem.
In your Controllers, there should be Auth/LoginController.php. There should be a variable in there protected $redirectTo. Just set that to a registered route and see if you are still having the same problem.
It seems like a permission error, try setting the right permission on your project's directory.
sudo chown -R :www-data path/to/your_project
After, cd path/to/your_project and run this command so set storage's folder permission:
sudo chmod -R 775 storage
Related
I have Laravel with Jetstream installed. How can I add a route to Fortify?
I've read through the whole readme:
https://github.com/laravel/fortify/blob/1.x/README.md
That readme provides ways to customize functionality but it doesn't show a way to add a new route to Fortify.
I can see the routes.php file in
/vendor/laravel/fortify/routes/routes.php
but you're not supposed to edit stuff in the vendor folder. If you edit anything inside the vendor folder, whenever you run a Composer update it will overwrite any of your changes when the files update.
Typically I think you'd have to do some sort of artisan command to get proper access to the corresponding files by publishing Fortify's resources like:
php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"
This would publish Fortify's actions to your app/Actions folder, etc
How can I add a new route to Fortify in the right way?
You should never touch or mess with vendor as it is immaculate.
By default the fortify routes located on /vendor/laravel/fortify/routes/routes.php, but you shouldn't edit anything inside the vendor folder otherwise whenever you run composer update it will overwrite any of your changes when the files update.
You can simply do the same on /routes/web.php with fortify middleware :
Route::group(['middleware' => config('fortify.middleware', ['web'])], function () {
// with fortify guest middleware
Route::get('foo', function () {
return 'Foo';
})->middleware(['guest']);
// with fortify auth middleware
Route::get('bar', function () {
return 'bar';
}) ->middleware(['auth']); // fortify auth middleware
});
I just made a fresh laravel project from scratch and the first thing I did was, I executed
php artisan make:auth
then migrate it
php artisan migrate
and open the project in the browser and hit login it says
Sorry, the page you are looking for could not be found.
Here is the error screenshot:
and here is the routes/web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Maybe it works for you
First, go to the project directory and open the public folder and copy .htaccess and index.php to the main directory.
And Paste it Here in the Main Directory.
Then open the index.php and replace
require __DIR__.'/../vendor/autoload.php';
and $app = require_once __DIR__.'/../bootstrap/app.php';
with require __DIR__.'/vendor/autoload.php';
and
$app = require_once __DIR__.'/bootstrap/app.php';
and save it. then run the project in the browser
Localhost:8080/bsms/login.
Use this command:
php artisan serve
If you have PHP installed locally and you would like to use PHP's built-in development server to serve your application, you may use the serve Artisan command. This command will start a development server at http://localhost:8000
Later you can check in browser like this: http://localhost:8000/login
If you have to check without artisan serve
you can check like this(bsms is your laravel-project-name):http://localhost/bsms/public/login
you must have a configuration like this in your .htaccess file
i've been stumped by thhis one for a couple of days now. I get this error when i try loading the main page, I get the error in the title. I've asked this question here and tried putting dd() at the top of the page as well as running php artisan route:clear as well as other commands hoping I can get the home page to load. The funny thing is I can load the user login function no problem.
Here's my routes file:
<?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 controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('pages.home');
});
Route::auth();
View Structure:
I found my problem. I didnt notice this before, but my project in PhpStorm was being saved to a directory outside my VM. i apologize for not figuring this out earlier.
I need some advice, i have just installed a fresh 5.2.37 version of Laravel.
Straight after the installation i setup the DB details in the .env file and then ran
php artisan make:auth
and then
php artisan migrate
Everything worked fine with no errors at all, when i view the index page of my site, i see the new landing page, but every time i click login or register it just returns 404's
There doesnt seem to be any login or register routes created, this is my routes.php file
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController#index');
There is an AuthController.php in the auth directory, but there is also no mention of a login or register route.
Have i missed a step?
Any help would be great.
Peace!
Run php artisan route:list command. You should see these routes:
login | ...\AuthController#showLoginForm
login | ...\AuthController#login
logout | ...\AuthController#logout
password/email | ...\PasswordController#sendResetLinkEmail
password/reset | ...\PasswordController#reset
password/reset/{token?} | ...\PasswordController#showResetForm
register | ...\AuthController#showRegistrationForm
register | ...\AuthController#register
If you see these commands, auth is work.
So, just go to http://you.app/register for example and you'll see registration form.
By default you can not the see the routes in your routes.php file.
As it returns 404 page , can you please check , site/index.php/register ?
Once you run the command , you should have an automated view in your app root directory.
From the navigation menu , you should be able to see the buttons to login and register.
Also you can check your database whether the table was created or not.
It turns out when installing the brand new Ubuntu Server box, i forgot to setup mod-rewrite.
I have just gone through and it all works perfect now.
Sorry for any inconvenience.
Peace!
I have been working with laravel 4 for some time now and i needed to create an admin area so i decided to use a package to keep things all organized and separated from the rest of the application.
So i created a package with composer as 'vendor/admin'.
then i added those lines as documemented on laravel site
AdminServiceProvider.php
public function boot()
{
$this->package('vendor/admin', 'admin');
include __DIR__.'/../../routes.php';
}
public function register()
{
//
$this->package('vendor/admin');
}
I also created a routes.php file in vedor/admin/ directory to route all admin area in this file.
following i run the 'php artisan dump-autoload' and i finalized with this commend on artisan 'php artisan config:publish vendor/admin'
now i wanna be able use this package for mysite.com/admin route and i want the routes.php file in the package to render the routing for that URI, to do that:
Do i need to modify my app/routes.php?
How can i make vendor/admin/src/routes.php file to do the routing for all mysite.com/admin routes?
Thanks.
No you don't need to edit app/routes.php. As long as it doesn't contain any admin routes that could collide with the ones in your package you can leave it that way.
The routes file in a package can be used like the "normal" app/routes.php. An easy way to deal with admin routes is to have a prefix group:
Route::group(array('prefix' => 'admin'), function(){
// all your admin routes. for example:
Route::get('dashboard', '...');
// will match GET /admin/dashboard
});
Besides that, make sure you're package gets loaded correctly! One part being registering the service provider. Assuming the namespace of your package is Admin you need to add Admin\AdminServiceProvider to the providers array in app/config/app.php. More information