0
Good evening, I am with a project being done in the Standard 5.8 and I have a certain problem, in short the project works in my work, but does not work at home.
The point is, the project opens and runs normally in the place where I work, which is where I did it all. I created a repository. git and cloned the project to work at home, copied the . env and put at home, I used Composer and npm install, all right, I installed the same version of php and IIS Express and managed the mysql database. The project up runs at home, displays most of the screens. But I’m basically in 2 problems:
1- The login (done with make:auth) is not performed, even with the information inserted correctly, when you click on login it returns to the same screen without logging in. On the other hand, when registering, the registration is done correctly and redirects with the logged-in user. If I log out with this user, I can’t log in anymore (back to the initial problem).
2- I created a profile screen for the user, however, when accessing it is returning error with the following message: "Method Illuminate Database Eloquent Collection::user does not exist".
The error occurs in the following function of my Profilecontroller:
public function show($username){
$user_id = User::select('id')->where('username', $username)->first();
$profile = User::find($user_id)->user();
return view('perfil/perfil', ['profile'=>$profile]);
}
Specifically on the line $profile = User::find ($user_id)->user();
.
Profile Model:
class Profile extends Model
{
protected $fillable = [
'user_id','main_sheet', 'main_camp', 'age', 'location', 'avatar'
];
public $timestamps = false;
public function user(){
return $this->belongsTo(User::class);
}
}
User Model:
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'username'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function profile(){
return $this->hasMany(Profile::class);
}
}
Anyway, these are the problems I’m having. Remembering that the project works perfectly in my workplace. Both the login and the profile screen, I’ve tried several things, but nothing solved.
Thank you very much to anyone who can help.
The
Model User
has no relationshipuser
has the relationshipprofile()
: problem line:$profile = User::find($user_id)->user();
, should be$profile = User::find($user_id)->profile();
Your problem is not that Laravel runs at work and does not run at home your problem is wrong programming even using things that do not exist inmodel
...– novic
Another problem the line
$user_id = User::select('id')->where('username', $username)->first();
return a die like this$user_id->id
and the next line should be$profile = User::find($user_id->id)->profile();
, summarizing the problem really is in programming. Note if the lines work it is like this if you do not have to check if returned– novic
Good morning. In fact the observations that Voce made are pertinent, by changing what said the profile screen worked, however, the programming is identical to that of my work and there it works, this I find strange. Another thing is that the login screen still does not work, and there it works perfectly. Thank you very much for the attention
– Guilherme Politano
Sincerity I doubt that the codes are the same, after all now worked out with my fixes.
– novic
I can only demonstrate this on Monday by taking prints, but yes, they are the same, including I gathered yesterday for the github and compared everything to make sure it was the same. What might be is that maybe I changed things at work for testing and I don’t remember, but I don’t. Anyway, the login I’m sure there was no change and the files are identical. Taking advantage, how do I pull the controller information to the screen after these changes? Before was {{$profile->avatar}}, now giving Undefined, because the avatar does not have in the table User, only in Profile. Thanks
– Guilherme Politano
Boy I doubt again, look at your new doubt... let me see your github? because if the avatar is in profile on that line is returning profile it is only use if the die is present ... See how code behave differently if one is wrong.
– novic
I can yes https://github.com/guipolitano/studies/tree/master/dnd
– Guilherme Politano
is nothing more wrong than what is there! the relationship is wrong ... Get... enough things are wrong
– novic
Hauahuh, I’m quite a beginner yet. This project is just to learn, of course it will have many errors =P What strange me is not working at home and working at work =/
– Guilherme Politano
So oooooooo something strange must be code Harry Potter ... is magic kkk
– novic