Method Illuminate\Database\Eloquent\Collection::user does not exist. #1081
Unanswered
Trevorkeya
asked this question in
Q&A
Replies: 1 comment
-
Use a where clause to only load the right records rather than using if statements. If you post your full component then I can give you a steer . Please use the code tags so that it keeps its formatting. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to show all posts of a user but in trying to pass an if statement I'm getting the above error
here is my blade file:
@if(Auth::user()->id == $county->user()->id)
@foreach($county as $county)
{{$county->title}}
{{$county->body}}
{{date('Y-m-d ', strtotime($county->created_at)) }}
here is my profile controller;
validate([ 'username' => ['required','string'], 'phone' => ['required','digits:10'], 'status' => ['required','string'], 'organization' => ['required','string'], 'image' => 'required|image', ]); $user = User::findOrFail(Auth::user()->id); $user->update([ 'name' => $request->username ]); $user->profile()->updateOrCreate( [ 'user_id' => $user->id, ], [ 'phone' => $request->phone, 'status' =>$request->status, 'organization' => $request->organization, 'image' => $request->image, ] ); $file=$request->image; $imageName = time().'.'.$request->image->extension(); $request->image->move(public_path('images'), $imageName); $user->image=$imageName; return redirect('/profile')->with('success','User Profile Updated Successfully!'); } } here is my User model */ protected $fillable = [ 'name', 'email', 'password', 'role_as', ]; public function profile() { return $this->hasOne(Profile::class, 'user_id','id'); } public function county() { return $this->hasMany(county::class); } /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; } heres my county model belongsTo(User::class); } }Beta Was this translation helpful? Give feedback.
All reactions