'Posts are not displaying on the Profile page

I am doing an Instagram clone project and I have encountered a tricky problem because, there is no error really, but the app is not functioning like its supposed to. Basically, I have added a functionality to instagram web application, where the user can add a post. Once the user uploads the image and caption, the create post page is supposed to redirect back to their profile. Which it does, perfectly. But the problem is, the uploaded posts are not displaying on the profile. Here is how my index.blade looks like

   <div class="d-flex">
                <div style="padding-right: 25px;"><strong>153</strong> posts</div>
                <div style="padding-right: 25px;"><strong>2M</strong> followers</div>
                <div style="padding-right: 25px;"><strong>300</strong> following</div>

            </div>
            <div><strong>{{$user->profile->title}}</strong></div>
            <div>{{$user->profile->description}}</div>
            <div><a href="#">{{$user->profile->url}}</a></div>
        </div>
        <div class="row pt-5">
            @foreach($user->posts as $post)
            <div class="col-4>
            <img src="storage/{{ $post->image }}" class="w-100">
            </div>
        @endforeach
        </div>
</div>

My PostsController

class PostsController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function create()
    {
    return view('posts.create');
    }

    public function store(Request $request)
    {
        $data = $request->validate([
                //'another =>'', Tells laravel to ignore all other fields
                
                'caption'=>'required',
                'image'=> 'required' ,
        ]);
        

        if($request->hasfile('image'))
        {
            $data = $request->file('image');
            $extension = $data->getClientOriginalExtension();
            $filename = time().'.'.$extension;
            $data->storeAs('uploads/public/', $filename);
        }


        $data = Auth::user()->posts()->create([
            'caption'=>$request->caption,
            'image'=>$request->image,
        ]);

        $data = Auth::id();

        return redirect()->route('Profile.show', [$data]);
       
        //goes ahead and grabs the authenticated user
      
    }
}

My routes

Route::get('/p/create', [App\Http\Controllers\PostsController::class, 'create'])->name('posts.create');

Route::post('/p', [App\Http\Controllers\PostsController::class, 'store']);

Route::get('/Profile/{user}', [App\Http\Controllers\ProfilesController::class, 'index'])->name('Profile.show');


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source