mlazuardy's avatar

Get Blog Post On User Profile

the next step of making User Profile has complete, but i have a new problem again and again.

so i create the show profile method on ProfilesController.php like

<?php

namespace App\Http\Controllers;
use Alert;
use Illuminate\Http\Request;
use App\Profile;
use App\User;

use Illuminate\Support\Facades\Input;
class ProfilesController extends Controller
{


    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($username)
    {
        //
        $user = $this->getUserByUsername($username);

        return view('profile.show')->withUser($user);
    }


    public function getUserByUsername($username)
        {
            return User::with('profile')->whereUsername($username)->firstOrFail();
        }
    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
     public function edit($username)
        {
            $user = $this->getUserByUsername($username);
            return view('profile.edit')->withUser($user);
        }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $username)
    {
      $user = $this->getUserByUsername($username);
      $input = Input::only('location','bio','twitter_username','github_username','facebook_username','instagram_username');
      if ($user->profile == null) {
            $profile = new Profile();
            $profile->fill($input);
            $user->profile()->save($profile);
        } else {
            $user->profile->fill($input)->save();
        }



        $user->save();

          return redirect('profile/'.$user->username.'/edit')->with('success','Profil Telah di Update');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

on the show page who contain user profile that can show for any user (auth or just a guess) and showing the post they create but the problem is how to looping with for each and also use pagination on this ProfileController?

0 likes
0 replies

Please or to participate in this conversation.