i'm trying to build a hyperlink from index.blade.php to login.blade.php by route. i defined a named route for this hyperlink but is not working.
here is my route code.
Route::get('/','HomeController#index');
Route::get('/login', 'HomeController#login_page')->name('login');
and here is my controller.
public function login_page()
{
return view('login');
}
and here is my view where i'm trying to set a hyperlink.
<li>Log-in</li>
Set URL link in a menu link using Laravel blade template, use it {{url('dashboard')}}. Use this link in the for example:
<ul>
<li>
Dashboard
</li>
</ul>
I think it will be helpful for you.
Your error message points to a server problem, not Laravel.
Make sure you'r mod_rewrite for apache is installed and enabled.
a2enmod rewrite
service apache2 restart
Then check your Laravel with:
In your console, run: php artisan route:list and see if you have a row similar to:
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------+---------------+---------------------------------------------------+-----------------------------+
| | GET|HEAD | login | login | App\Http\Controllers\HomeController#login_page | web,guest |
If you do not see the login part, try clearing route's cache with:
php artisan route:clear
Other than that, you are doing everything properly.
I had the same problem (Ubuntu 18.04), it does not seem to be Laravel but Apache.
Workaround: Install Xampp and use it as Localhost.
Related
directory structure
laravel package
| |-project1
| |-app
| |-config
| |-resources
| |-project2
| |-app
| |-config
| |-resources
|-env
| and other files
|
i need the folder structure to be like above mentioned.please mention as tutorial as i am new to laravel. as i like to run multiple projects in the same laravel package without installing a new package sharing other files like env ,vendor etc.,
You could do something like this:
You can namespace all files under the app folder and prefix everything with 'project1', 'project2', etc
App/Project1/Models/etc...
App/Project1/Controllers/etc...
App/Project2/Models/etc...
App/Project2/Controllers/etc...
And in your route files, connect the routes to the different namespaces:
Route::group(['namespace' => 'App\Project1\Controllers'], function()
{
Route::get('/', 'HomeController#index');
});
You can even make different route files for different projects and load them through the RouteServiceProvider#map method...
But to be honest, I would never go this way. Laravel is so easy to load through composer, what is the problem? The whole system runs so smoothly, why try to introduce these dimensions? But if you really want to, there is always a way... :-)
I'm trying upgrade my laravel project from 5.2 to 5.3.
Since laravel 5.3, the route files are kept in a separate directory routes, instead of the previous app\Http directory. I created the file routes/web.app and pasted my routes into this file.
When i execute php artisan route:list, it returns:
+--------+----------+-------------------+------+--------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------+------+--------------------------------------------+------------+
| | GET|HEAD | captcha/{config?} | | \Mews\Captcha\CaptchaController#getCaptcha | web |
+--------+----------+-------------------+------+--------------------------------------------+------------+
My routes/web.php file:
<?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(){
echo 'here';
});
Where is my route?
When I access the home page, it returns a 404 error, but the error comes from laravel.
The file .htaccess is ok.
You said:
I created the file routes/web.app and past my routes on file.
In Laravel 5.3 the web.php file is already created in the routes directory. If you have recreated this file that is where the problem may be propagating from.
I read the upgrade documentation and thought I needed to remove the EventServiceProvider, RouteServiceProvider, AuthServiceProvider methods from the boot ....
But in fact I needed to update the contents of these files.
After updating the contents to the new version 5.3 up to where I tested, it is working ....
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 installed a project on my www folder in wamp , but when i add new route and try to get it wil the browser i got page not found , i copied all laravel 4 files to local folder exclude publi folder and i put its content on www , and try my route , i got the same error :
the routes :
<?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::get('/', function()
{
return View::make('hello');
});
Route::get('about', function()
{
return View::make('hello');
});
when i get to " localhost " , it works fine but when i get to " localhost/about" i got page not found and i modified paths and index files and same issue
you can enable rewrite_mod :
Open the httpd.conf file and search for
"rewrite"
, then remove
"#"
at the starting of the line,so the line looks like.
LoadModule rewrite_module modules/mod_rewrite.so
then restart the wamp.
It's likely that rewrite_mod is disabled in your Apache installation.
Try enabling it. Here's how to do it