DNAngel

DNAngel

Member Since 3 Years Ago

Experience Points 650
Experience Level 1

4,350 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 1
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

19 Jul
3 years ago

DNAngel left a reply on Check Current Users Permission To Update Article

My opinion is that include a user_id column in the article database, and then you may use relation to get the article user_id and check whether it is Auth::user()->id before allowing someone using the edit/update button.

DNAngel left a reply on @yield

As it is telling you that, it can't locate the app.blade.php. You might have included it somewhere-else.

To solve that issue, you can create app.blade.php in view folder.

<!DOCTYPE html>
    <head>
        <meta charset='utf-8'>
        <title>About Page</title>
    </head>
    <body>
        @section('content')
        @stop
    </body>
</html>

DNAngel left a reply on Infinite Scroll Repeated The Last Result

@david001 HomeController.php

class HomeController extends Controller {

    public function index(Request $request) {

        if(Auth::check()) {

            $statuses = Status::NotReply()->NotFriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            });

            $friendPosts = Status::NotReply()->FriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            });

            $collection = collect($statuses->get());
            $allStatuses = $collection->merge($friendPosts->get())->sortByDesc('updated_at');

            $allStatuses = PaginateController::paginateClients($allStatuses);

            if($request->ajax()) {

                return [
                    'allStatuses' => view('timeline.ajax.index')->with('allStatuses', $allStatuses)->render(),
                    'next_page' => $allStatuses->nextPageUrl()
                ];
            }

            return view('timeline.index')->with('allStatuses', $allStatuses);
        }

        return view('home');
    }
}

Route.php

Route::get('/', [
    'uses' => '\App\Http\Controllers\[email protected]',
    'as' => 'home',
]);

Route::get('/ajax', [
    'uses' => '\App\Http\Controllers\[email protected]'
]);
18 Jul
3 years ago

DNAngel left a reply on How To Set Up Polymorph And Store It? Need Help

That means you have two models: Song and Artist

If I got your goal right, you want to create a polymorphic (The Highlight of the Week) for those two models.

Highlight.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Highlight extends Model {

    protected $table = "highlightable";

    public function highlightable() {

        return $this->morphTo();
    }

    public function user() {

        return $this->belongsTo('App\Models\User', 'user_id');
}

Song.php


namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Song extends Model {

    protected $table = "Songs";

    public function highlight() {

        return $this->morphMany('App\Models\Highlight', 'highlightable');
    }
}

Artist.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Artist extends Model {

    protected $table = "Artists";

    public function highlight() {

        return $this->morphMany('App\Models\Highlight', 'highlightable');
    }
}

Also, the way you created your migration for polymorphic might not be right. (If I got what you mean)

Schema::create('hightlightable', function(Blueprint $table) {
    $table->increment('id'); //optional
    $table->integer('user_id');
    $table->integer('highlightable_id');
    $table->string('hightightable_type');
    $table->timestamps();
});

In your controller might be:

public function toHighlight($song_id) {
    
    $highlight = Song::find($song_id)->highlight()->create([]);
    
    Auth::user()->highlight()->save($highlight);
}

In your User.php model

public function highlight() {

    return hasMany('App\Models\Highlight', 'user_id');
}

DNAngel left a reply on How To Set Up Polymorph And Store It? Need Help

Polymorphic is a function for you to share one model to other models. You might need to read it here https://laravel.com/docs/5.1/eloquent-relationships#polymorphic-relations

From your goal, I don't think polymorphic is what you are looking for. Your goal sounds more like randomizing a song lists.

DNAngel left a reply on @yield

Route.php

Route::get('/1/{name}', 'uses' => '[email protected]');

Homecontroller.php

namespace App\Http\Controllers;

class Homecontroller extends Controller {

    public function index() {
        return view('home');
    }

    public function test($name) {
        return view('testc', $name);
    }
}

views/testc.blade.php :

@extends('layouts.testp')

@section('content')
    <div>{{ $name about us page here }}</div>
@stop

views/layouts/testp.blade.php :

@section('content')

DNAngel left a reply on Infinite Scroll Repeated The Last Result

@jlrdw ,Yes, it is correct. There are only 9 items showing without ajax. When I went to ?page=2, it sometimes duplicated the last 3 items after scrolling to the the bottom. It might have something to do with the closing condition.

17 Jul
3 years ago

DNAngel started a new conversation Infinite Scroll Repeated The Last Result

When I dd($allStatuses), it gave 9 items. My pagination is 3 items per page. When I scrolled my homepage to the bottom, it repeated the last 3 items once.

I tried ?page=4, and it resulted none. When I tried ?page=3 and scrolled down, it repeated the same items in ?page=3 once.

<script>

    $(document).ready(function() {

        $(window).scroll(fetchPosts);

        function fetchPosts() {
            var page = $('.endless-pagination').data('next-page');
            if(page !== null) {

                clearTimeout($.data(this, "scrollCheck"));

                $.data(this, "scrollCheck", setTimeout(function() {
                    var scroll_position_for_posts_load = $(window).height() + $(window).scrollTop() + 100;

                    if(scroll_position_for_posts_load >= $(document).height()) {
                        $.get(page, function(data) {
                            $('.allStatuses').append(data.allStatuses);
                            $('.endless-pagination').data('next-page', data.next_page);
                        });
                    }
                }, 350));
            }
        }
    });
</script>
14 Jul
3 years ago

DNAngel left a reply on Laravel Pagination Not Working With Array Instead Of Collection

@Francismori7 Thanks for replying my message.

I applied your paginateClients() in the HomeController.php

$allStatuses = PaginateController::paginateClients($allStatuses); so I have to change the protected to public. Would that be a problem?

class HomeController extends Controller {

    public function index(Request $request) {

        if(Auth::check()) {

            $statuses = Status::NotReply()->NotFriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            });

            $friendPosts = Status::NotReply()->FriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            });

            $collection = collect($statuses->get());
            $allStatuses = $collection->merge($friendPosts->get())->sortByDesc('created_at');

            $allStatuses = PaginateController::paginateClients($allStatuses);

            if($request->ajax()) {

                return view('timeline.ajax.index')->with('allStatuses', $allStatuses)->render();
            }

            return view('timeline.index')->with('allStatuses', $allStatuses);
        }

        return view('home');
    }
}

Also, could you please explain the line below from your script:

if (!$paginatedClients->isEmpty()) {
        $query = $paginatedClients->first()->newQuery()->with('orders');
        $paginatedClients = Collection::make($query->eagerLoadRelations($paginatedClients->all()));
    }

I could not get it to work unless I deleted the with('orders'). It gives me undefined error. Your script is awesome, but I really want to fully understand it.

13 Jul
3 years ago

DNAngel left a reply on Laravel Pagination Not Working With Array Instead Of Collection

I have a few things that I don't understand with this script from @Francismori7:

    /**
     * Paginates a collection of clients.
     *
     * @param Collection $allClients The collection containing all clients.
     * @return LengthAwarePaginator
     */
    protected static function paginateClients(Collection $allClients)
    {
        $currentPage = LengthAwarePaginator::resolveCurrentPage() ?: 1;
        $startIndex = ($currentPage * self::MAX_CLIENTS_PER_PAGE) - self::MAX_CLIENTS_PER_PAGE;
        $paginatedClients = Collection::make($allClients)->slice($startIndex, self::MAX_CLIENTS_PER_PAGE);

        /*
         * Eager load orders for each client, but we don't want those cached.
         */
        if (!$paginatedClients->isEmpty()) {
            $query = $paginatedClients->first()->newQuery()->with('orders');
            $paginatedClients = Collection::make($query->eagerLoadRelations($paginatedClients->all()));
        }
        return new LengthAwarePaginator(
            $paginatedClients,
            $allClients->count(),
            self::MAX_CLIENTS_PER_PAGE,
            $currentPage, 
            [
                'path' => LengthAwarePaginator::resolveCurrentPath(),
            ]
        );
    }

Why is the paginateClients() is protected instead of public? I thought static should be in public. Also, I included public static $MAX_CLIENTS_PER_PAGE = 1 and added a string to all the self::MAX_CLIENTS_PER_PAGE becoming self::$MAX_CLIENTS_PER_PAGE. Am I doing it right?

12 Jul
3 years ago

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

Yes, I missed the ->get(). Thanks.

$collection = collect($statuses->get());
$allStatuses = $collection->merge($friendPosts->get())->sortByDesc('created_at')->forPage(2,5);

The code above does not give me the second page. Is there a function that could work like paginate(n) that could automatically detect the the length of an array and assign n number of things per page ?

11 Jul
3 years ago

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

$statuses = Status::NotReply()->NotFriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            });

            $friendPosts = Status::NotReply()->FriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            });

I tried merging the two arrays above as the following:

$collection = collect($statuses);
$allStatuses = $collection->merge($friendPosts)->all();

When I dd($allStatuses), it shows me like the one at below. I don't see any values from the database.

array:8 [▼
  "\x00*\x00query" => Builder {#184 ▶}
  "\x00*\x00model" => Status {#185 ▶}
  "\x00*\x00eagerLoad" => []
  "\x00*\x00macros" => []
  "\x00*\x00onDelete" => null
  "\x00*\x00passthru" => array:11 [▶]
  "\x00*\x00scopes" => []
  "\x00*\x00removedScopes" => []
]

I think the way that I merged them is wrong.

10 Jul
3 years ago

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

Ah... merge. Okay, will try that.

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

I see. Is there other options for the arrays that do not have the same length?

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

I dd() the $friendPosts[$index]->user->username, and it did give me a value.

Regarding the $index, I was trying to do foreach for two different arrays. I wanna output the status post and the friendPost on timeline. So, with the $index, that allows me to output two different arrays in the same foreach.

@foreach($statuses as $index => $status)
 @include('timeline.partials.statusblock')
 @include('timeline.partials.friendtofriendstatusblock')
@endforeach

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

Line 2 from ErrorException in b836960d8afb261ac0cd337b0ac052bd22c615b4.php

<a class="pull-left" href="<?php echo e(route('profile.index', ['username' => $friendPosts[$index]->user->username])); ?>">

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

Yes, the code above did display the time. I don't understand why the way I used it is wrong. I want to run two different arrays in one foreach loop. This is why I did @foreach($statuses as $index => $status), $status and $friendPosts[$index].

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

Code that involves this line $friendPosts[$index] is giving that error mentioned in the first post. However, I dd() each of the code that involves $friendPosts[$index], and it gives value. I don't understand what's going on.

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

I meant I deleted the rest of it and left only the body and created_at in the file. They both did give me values with the dd(), but when I re-ran the script below it gave me the same error.

<div class="media">
    <a class="pull-left" href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">
        <img class="media-object" alt="{{ $friendPosts[$index]->user->getNameOrUsername() }}" src="{{ $friendPosts[$index]->user->getAvatarUrl() }}">
    </a>
    <div class="media-body">
        <h4 class="media-heading"><a href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">{{ $friendPosts[$index]->user->getNameorUsername() }}</a></h4>
        <p>{{ $friendPosts[$index]->body }}</p>
        <ul class="list-inline">
            <li>{{ $friendPosts[$index]->created_at->diffForHumans() }}</li>
        </ul>

    </div>
</div>

DNAngel left a reply on Laravel 5: Trying To Get Property Of Non-object

Nope, none of them returned null. I checked each of them, and they did return values. I deleted some of the parts in the script below, but it's giving me the same error.

timeline/partial/friendtofriendstatusblock.blade.php

<div class="media">
    <a class="pull-left" href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">
        <img class="media-object" alt="{{ $friendPosts[$index]->user->getNameOrUsername() }}" src="{{ $friendPosts[$index]->user->getAvatarUrl() }}">
    </a>
    <div class="media-body">
        <h4 class="media-heading"><a href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">{{ $friendPosts[$index]->user->getNameorUsername() }}</a></h4>
        <p>{{ $friendPosts[$index]->body }}</p>
        <ul class="list-inline">
            <li>{{ $friendPosts[$index]->created_at->diffForHumans() }}</li>
        </ul>

    </div>
</div>

DNAngel started a new conversation Laravel 5: Trying To Get Property Of Non-object

Received this error

ErrorException in b836960d8afb261ac0cd337b0ac052bd22c615b4.php line 2:
Trying to get property of non-object (View: C:\wamp64\www\peepbox\resources\views\timeline\partials\friendtofriendstatusblock.blade.php) (View: C:\wamp64\www\peepbox\resources\views\timeline\partials\friendtofriendstatusblock.blade.php)

HomeController.php

class HomeController extends Controller {

    public function index(Request $request) {

        if(Auth::check()) {

            $statuses = Status::NotReply()->NotFriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            })->orderBy('created_at', 'desc')->paginate(4);

            $friendPosts = Status::NotReply()->FriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            })->orderBy('created_at', 'desc')->paginate(4);


            if($request->ajax()) {

                return view('timeline.ajax.index')->with('statuses', $statuses)->with('friendPosts', $friendPosts)->render();
            }

            return view('timeline.index')->with('statuses', $statuses)->with('friendPosts', $friendPosts);
        }

        return view('home');
    }
}

timeline/indexx.blade.php

@extends('templates.default')

@section('content')
<div class="row">
    <div class="col-lg-6">
        <form role="form" action="{{ route('post.status') }}" method="post">
            <div class="form-group{{ $errors->has('status') ? ' has-error' : '' }}">
                <textarea placeholder="What's up {{ Auth::user()->getFirstNameOrUsername() }}?" name="status" class="form-control" rows="2"></textarea>
                @if($errors->has('status'))
                    <span class = "help-block">{{ $errors->first('status') }}</span>
                @endif
            </div>
            <button type="submit" class="btn btn-default">Post status</button>
            <input type = "hidden" name = "_token" value = "{{ Session::token() }}">
        </form>
        <hr>
    </div>
</div>

<div class="row">
    <div class="col-lg-5">
        @if(!$statuses->count())
            <p>There's nothing in your timeline yet.</p>
        @else
            @foreach($statuses as $index => $status)
                @include('timeline.partials.statusblock')
                @include('timeline.partials.friendtofriendstatusblock')
            @endforeach
            {{ $statuses->render() }}
            {{ $friendPosts->render() }}

        @endif
    </div>
</div>
@stop
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script>

$document.ready(function() {

    $('body').on('click', '.pagination a', function(e) {

        e.preventDefault();
        var page = $(this).attr('href');
        
        $.get(page, function(data) {
            $('.statuses').html(data);
        });
    });
});
    
</script>

timeline/partial/friendtofriendstatusblock.blade.php

<div class="media">
    <a class="pull-left" href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">
        <img class="media-object" alt="{{ $friendPosts[$index]->user->getNameOrUsername() }}" src="{{ $friendPosts[$index]->user->getAvatarUrl() }}">
    </a>
    <div class="media-body">
        <h4 class="media-heading"><a href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">{{ $friendPosts[$index]->user->getNameorUsername() }}</a></h4>
        <p>{{ $friendPosts[$index]->body }}</p>
        <ul class="list-inline">
            <li>{{ $friendPosts[$index]->created_at->diffForHumans() }}</li>
            @if($friendPosts[$index]->likes->where('user_id', Auth::user()->id)->count() === 1)
                <li><a href="{{ route('unlike.status', ['status_id' => $friendPosts[$index]->id]) }}">Unlike</a></li>
            @elseif(Auth::user()->isFriendsWith($friendPosts[$index]->user) || Auth::user()->id === $friendPosts[$index]->user->id)
                <li><a href="{{ route('like.status', ['status_id' => $friendPosts[$index]->id]) }}">Like</a></li>
            @endif
            @if($friendPosts[$index]->likes->count() !== 0)
                <li>{{ $friendPosts[$index]->likes->count() }} {{ str_plural('like', $friendPosts[$index]->likes->count()) }}</li>
            @endif
        </ul>
        @foreach($friendPosts[$index]->replies as $reply)
            <div class="media">
                <a class="pull-left" href="{{ route('profile.index', ['username' => $reply->user->username]) }}">
                    <img class="media-object" alt="{{ $reply->user->getNameOrUsername() }}" src="{{ $reply->user->getAvatarUrl() }}">
                </a>
                <div class="media-body">
                    <h5 class="media-heading"><a href="{{ route('profile.index', ['username' => $reply->user->username]) }}">{{ $reply->user->getNameOrUsername() }}</a></h5>
                    <p>{{ $reply->body }}</p>
                    <ul class="list-inline">
                        <li>{{ $reply->created_at->diffForHumans() }}</li>
                        @if($reply->likes()->where('user_id', Auth::user()->id)->count() > 0)
                            <li><a href="{{ route('unlike.status', ['status_id' => $reply->id]) }}">Unlike</a></li>
                        @elseif(Auth::user()->isFriendsWith($friendPosts[$index]->user)  || Auth::user()->id === $reply->user->id || Auth::user()->id === $friendPosts[$index]->user->id)
                            <li><a href="{{ route('like.status', ['status_id' => $reply->id]) }}">Like</a></li>
                        @endif
                        @if($reply->likes->count() !== 0)
                            <li>{{ $reply->likes->count() }} {{ str_plural('like', $reply->likes->count()) }}</li>
                        @endif
                    </ul>
                </div>
            </div>
        @endforeach
        
        <form role="form" action="{{ route('reply.status', ['status_id' => $friendPosts[$index]->id, 'username' => $friendPosts[$index]->user->username]) }}" method="post">
            <div class="form-group{{ $errors->has("reply-{$friendPosts[$index]->id}") ? ' has-error' : '' }}">
                <textarea name="reply-{{ $friendPosts[$index]->id }}" class="form-control" rows="2" placeholder="Reply to this status"></textarea>
                @if($errors->has("reply-{$friendPosts[$index]->id}"))
                    <span class="help-block">{{ $errors->first("reply-{$friendPosts[$index]->id}") }}</span>
                @endif
            </div>
            <input type="submit" value="Reply" class="btn btn-default btn-sm">
            <input type="hidden" name="_token" value="{{ Session::token() }}">
        </form>
    </div>
</div>

I think the problem is because of this @foreach($statuses as $index => $status), and causes error on this ['username' => $friendPosts[$index]->user->username] which is in friendtofriendstatusblock.blade.php

06 Jul
3 years ago

DNAngel left a reply on Laravel 5.1 Multiple Paginate In One Page

Bumb. Still need help on this.

05 Jul
3 years ago

DNAngel started a new conversation Laravel 5.1 Multiple Paginate In One Page

HomeController.php


        if(Auth::check()) {

            $statuses = Status::NotReply()->NotFriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            })->orderBy('created_at', 'desc')->paginate(4, ['*'], 'statuses');

            $friendPosts = Status::NotReply()->FriendPostUserProfile()->where(function($query) {
                return $query->where('user_id', Auth::user()->id)
                            ->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
            })->orderBy('created_at', 'desc')->paginate(4, ['*'], 'friendPosts');

            return view('timeline.index')->with('statuses', $statuses)->with('friendPosts', $friendPosts);
        }

        return view('home');
    }
}

timeline\partials\friendtofriendstatusblock,php

<div class="media">
    <a class="pull-left" href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">
        <img class="media-object" alt="{{ $friendPosts[$index]->user->getNameOrUsername() }}" src="{{ $friendPosts[$index]->user->getAvatarUrl() }}">
    </a>
    <div class="media-body">
        <h4 class="media-heading"><a href="{{ route('profile.index', ['username' => $friendPosts[$index]->user->username]) }}">{{ $friendPosts[$index]->user->getNameorUsername() }}</a></h4>
        <p>{{ $friendPosts[$index]->body }}</p>
        <ul class="list-inline">
            <li>{{ $friendPosts[$index]->created_at->diffForHumans() }}</li>
            @if($friendPosts[$index]->likes->where('user_id', Auth::user()->id)->count() === 1)
                <li><a href="{{ route('unlike.status', ['status_id' => $friendPosts[$index]->id]) }}">Unlike</a></li>
            @elseif(Auth::user()->isFriendsWith($friendPosts[$index]->user) || Auth::user()->id === $friendPosts[$index]->user->id)
                <li><a href="{{ route('like.status', ['status_id' => $friendPosts[$index]->id]) }}">Like</a></li>
            @endif
            @if($friendPosts[$index]->likes->count() !== 0)
                <li>{{ $friendPosts[$index]->likes->count() }} {{ str_plural('like', $friendPosts[$index]->likes->count()) }}</li>
            @endif
        </ul>
        @foreach($friendPosts[$index]->replies as $reply)
            <div class="media">
                <a class="pull-left" href="{{ route('profile.index', ['username' => $reply->user->username]) }}">
                    <img class="media-object" alt="{{ $reply->user->getNameOrUsername() }}" src="{{ $reply->user->getAvatarUrl() }}">
                </a>
                <div class="media-body">
                    <h5 class="media-heading"><a href="{{ route('profile.index', ['username' => $reply->user->username]) }}">{{ $reply->user->getNameOrUsername() }}</a></h5>
                    <p>{{ $reply->body }}</p>
                    <ul class="list-inline">
                        <li>{{ $reply->created_at->diffForHumans() }}</li>
                        @if($reply->likes()->where('user_id', Auth::user()->id)->count() > 0)
                            <li><a href="{{ route('unlike.status', ['status_id' => $reply->id]) }}">Unlike</a></li>
                        @elseif(Auth::user()->isFriendsWith($friendPosts[$index]->user)  || Auth::user()->id === $reply->user->id || Auth::user()->id === $friendPosts[$index]->user->id)
                            <li><a href="{{ route('like.status', ['status_id' => $reply->id]) }}">Like</a></li>
                        @endif
                        @if($reply->likes->count() !== 0)
                            <li>{{ $reply->likes->count() }} {{ str_plural('like', $reply->likes->count()) }}</li>
                        @endif
                    </ul>
                </div>
            </div>
        @endforeach
        
        <form role="form" action="{{ route('reply.status', ['status_id' => $friendPosts[$index]->id, 'username' => $friendPosts[$index]->user->username]) }}" method="post">
            <div class="form-group{{ $errors->has("reply-{$friendPosts[$index]->id}") ? ' has-error' : '' }}">
                <textarea name="reply-{{ $friendPosts[$index]->id }}" class="form-control" rows="2" placeholder="Reply to this status"></textarea>
                @if($errors->has("reply-{$friendPosts[$index]->id}"))
                    <span class="help-block">{{ $errors->first("reply-{$friendPosts[$index]->id}") }}</span>
                @endif
            </div>
            <input type="submit" value="Reply" class="btn btn-default btn-sm">
            <input type="hidden" name="_token" value="{{ Session::token() }}">
        </form>
    </div>
</div>

ProfileController.php

class ProfileController extends Controller {

    public function getProfile($username) {
        
        $user = User::where('username', $username)->first();

        if(!$user) {

            abort(404);
        }

        $statuses = $user->statuses()->NotReply()->NotFriendPostUserProfile()->get();

        $friendPosts = $user->statuses()->NotReply()->FriendPostUserProfile()->get();

        return view('profile.index')
            ->with('user', $user)
            ->with('statuses', $statuses)
            ->with('friendPosts', $friendPosts)
            ->with('authUserIsFriend', Auth::user()->isFriendsWith($user));
    }

I received this error message:

ErrorException in b836960d8afb261ac0cd337b0ac052bd22c615b4.php line 2:
Trying to get property of non-object (View: C:\wamp64\www\peepbox\resources\views\timeline\partials\friendtofriendstatusblock.blade.php

I think the issue is because of ['username' => $friendPosts[$index]->user->username] in the friendtofriendstatusblock.php. The infomation could not be received by the ProfileController.php