BARNOWL
BARNOWL

Reputation: 3589

Laravel blade duplicating multiple buttons

I'm trying to show only one close button if a post belongs to a user by using utilize blade authentication however im getting this

enter image description here

The policy and server side runs ok and i can click the button and it will do as i need it to do, but i only need to see one close button for each post, however maybe im compacting the posts incorrectly.

html

 <div id="mypost" class="col-md-8 panel-default" ng-repeat="post in myposts">
        <div id="eli-style-heading" class="panel-heading"><% post.title %></div>
            <div class="panel-body panel">
                <figure>
                    <p> <% post.body %></p>
                   <p> by: <% post.user.name %></p>
                   <p>  <% post.created_at %></p>

                </figure>
                <span>


            @foreach($posts as $post)
                @if(Auth::user()->can('delete',$post))
                 <i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)"></i>
                @endif
            @endforeach

                </span>
            </div>
    </div>

PostController.php (the view for the posts page)

public function index()
{

    $posts = Post::with('user')->get();

    return view('home', compact('posts'));

}

Upvotes: 0

Views: 252

Answers (1)

jitender
jitender

Reputation: 10429

I don't know anything about php so i am writing simple text only

Its because you are using foreach inside ng-repeat Change

@foreach($posts as $post)// this is the problem 
                @if(Auth::user()->can('delete',$post))
                 <i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)"></i>
                @endif
            @endforeach

to

@foreach($posts as $post)
                @if(Auth::user()->can('delete',$post) && here add some condition like  $post.id(php)==post.id(angular))
                 <i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)"></i>
                @endif
            @endforeach

Or

@if(userIsAuthrise){
 <i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)"></i>
}

Upvotes: 1

Related Questions