I’m new to the Laravel framework, so I’m following this tutorial, cloning instagram.
After designing the front end, all was going well, until I started working with php artisan
.
I have created the user and profile database, migrated them successfully, and linked them in a one-to-one relationship.
But, after this, trying to login, and navigate to home, I’m getting a
404, not found error
I can’t seem to figure out what’s wrong.
profileController:
JavaScript
x
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class profilesController extends Controller
{
public function index($user)
{
$user = AppUser::find($user);
return view('home', [
'user' => $user,
]);
}
}
homeController:
JavaScript
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return IlluminateContractsSupportRenderable
*/
}
web.php:
JavaScript
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/profile/{user}', 'profilesController@index')->name('profile.show');
profile created via php artisan
JavaScript
$profile->user
=> AppUser {#2975
id: "1",
name: "Sofolahan Eniola Ademola",
email: "princeademola85@gmail.com",
username: "usertesst",
email_verified_at: null,
created_at: "2019-07-27 16:01:45",
updated_at: "2019-07-27 16:01:45",
}
>>> $profile
=> Appprofile {#2965
title: "cool stuff",
description: "desc stuff",
user_id: 1,
updated_at: "2019-07-27 16:04:45",
created_at: "2019-07-27 16:04:45",
id: 1,
user: AppUser {#2975
id: "1",
name: "Sofolahan Eniola Ademola",
email: "princeademola85@gmail.com",
username: "usertesst",
email_verified_at: null,
created_at: "2019-07-27 16:01:45",
updated_at: "2019-07-27 16:01:45",
},
}
Am I missing something?
Advertisement
Answer
By default, after a successful login, it directs you to ‘/home’ which is missing in your web route.
JavaScript
Route::get('/home', homeController@index')
You can replace homeController with the name of your controller and index with this method.