angelz.gutierrez

Experience

9,200

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 89 Lessons Completed
  • 2 Favorites

3rd March, 2018

angelz.gutierrez started a new conversation Folder Icons Not Loaded • 3 months ago

Hello guys,

'm having some issues when loading a folder inside public folder (public/icons). In my html i'm calling the svg like this:

So i tested it on my dev environment (same version, laravel 5.2) and it works fine, but on my prod server the images are not loaded, it returns a 404.

Any idea what am i missing?

I'm not using gulp, i'm loading the files directly.

Regards, Regis

27th November, 2017

angelz.gutierrez started a new conversation Android With Laravel ??? • 6 months ago

Hello everyone,

So we have an application built with Laravel, it is fully functional and works great. The thing is that I want to go mobile and develop some iOS and android apps. My question here is, should i write the app and the functionality from scratch ? Or just develop the app and then call an api ( Laravel ).

Regards, Ángel

7th November, 2017

angelz.gutierrez left a reply on Add Ajax Response To Current Li • 7 months ago

Hi,

I have a view that displays all my posts and each post contains a comment section ( like Facebook ).

That is why I was saying that I generated hundreds of li.

The Ajax url is /addComment and it gets the response it adds the html.

angelz.gutierrez left a reply on Add Ajax Response To Current Li • 7 months ago

Hello,

After the AJAX is executed, i got the returned html:

<ul id="comments" class="comments-list">
    <li>
        <div class="post__author author vcard inline-items">
            <img src="http://app.dev:8000/image/0/medium/1.8913ce8448cf76e0d6571847cf024428.jpg"
                 alt="author">

            <div class="author-date">
                <a class="h6 post__author-name fn" href="#">Test User</a>
                <div class="post__date">
                    <time class="published" datetime="2004-07-24T18:18">
                        5 minutes ago
                    </time>
                </div>
            </div>

            <a href="#" class="more">
                <svg class="olymp-three-dots-icon">
                    <use xlink:href="icons/icons.svg#olymp-three-dots-icon"></use>
                </svg>
            </a>
        </div>
        <p>
            Test comment
        </p>
    </li>
    <li>
        <div class="post__author author vcard inline-items">
            <img src="http://app.dev:8000/image/0/medium/1.8913ce8448cf76e0d6571847cf024428.jpg"
                 alt="author">

            <div class="author-date">
                <a class="h6 post__author-name fn" href="#">Test User</a>
                <div class="post__date">
                    <time class="published" datetime="2004-07-24T18:18">
                        2 minutes ago
                    </time>
                </div>
            </div>

            <a href="#" class="more">
                <svg class="olymp-three-dots-icon">
                    <use xlink:href="icons/icons.svg#olymp-three-dots-icon"></use>
                </svg>
            </a>
        </div>
        <p>
            Another test comment
        </p>
    </li>
    <li>
        <div class="post__author author vcard inline-items">
            <img src="http://app.dev:8000/image/0/medium/1.8913ce8448cf76e0d6571847cf024428.jpg"
                 alt="author">

            <div class="author-date">
                <a class="h6 post__author-name fn" href="#">Test User</a>
                <div class="post__date">
                    <time class="published" datetime="2004-07-24T18:18">
                        1 second ago
                    </time>
                </div>
            </div>

            <a href="#" class="more">
                <svg class="olymp-three-dots-icon">
                    <use xlink:href="icons/icons.svg#olymp-three-dots-icon"></use>
                </svg>
            </a>
        </div>
        <p>
            Test
        </p>
    </li>
</ul>

I got no error, i just want to update the current li i am using. As i previously said. I have a list of Post and a comment area below of it, if i go to Post number 1 and i add a comment the li is updated correctly but if i go to post #2 and then i add a comment, the comment appears but on li for post #1. After i reload the page the comments are displayed on the post that corresponds.

Regards,

angelz.gutierrez left a reply on Add Ajax Response To Current Li • 7 months ago

Sorry, my < li > were interpreted as an actual li.

angelz.gutierrez started a new conversation Add Ajax Response To Current Li • 7 months ago

Hello,

I'm creating a Post/Comment section for my webpage, so far i display all the Posts with their related comments.

I have a blade partial in which i display all comments:

<ul id="comments" class="comments-list">
    @foreach($post->comments as $comment)
        <li>
            <div class="post__author author vcard inline-items">
                     alt="author">

                <div class="author-date">
                    <a class="h6 post__author-name fn" href="#">{{ $comment->user->name }}</a>
                    <div class="post__date">
                        <time class="published" datetime="2004-07-24T18:18">
                            {{ $comment->created_at->diffForHumans() }}
                        </time>
                    </div>
                </div>

                <a href="#" class="more">
                    <svg class="olymp-three-dots-icon">
                        <use xlink:href="icons/icons.svg#olymp-three-dots-icon"></use>
                    </svg>
                </a>
            </div>
            <p>
                {{ $comment->comment }}
            </p>
        </li>
    @endforeach
</ul>

This is loaded and displayed correctly. As you can see this generates a lot of

  • 's tags and this is causing me some problems. When i add the html returned by the ajax call the comments are displayed right at the first
  • of the page, not to the current
  • i want.

    EX: I commented on the second post, the comment appears on the comment section of the first post.

    Here is my ajax call:

        $('form').on('submit', function(event){
            event.preventDefault();
            $.ajax({
                url: "/addComment",
                type: "POST",
                dataType: 'html',
                data: $(this).serialize(),
                success:function(data) {
                    $("#comments").html(data);
                }
            });
        });
    

    Any idea on how could i add the returned html to the current

  • (Post) i commented.

  • 5th November, 2017

    angelz.gutierrez left a reply on Can't Get Relationship • 7 months ago

    Hi,

    Yep, this {{ !empty($like->user->username) ? $like->user->username : '' }} did the trick. I'm getting all the information now.

    Thank you very much man.

    angelz.gutierrez left a reply on Can't Get Relationship • 7 months ago

    Hello, my controller remains the same:

        public function index()
        {
            $posts = Post::orderBy('id', 'desc')->with('like', 'like.user')->get();
    
            return view('frontend.home.home', compact('posts', $posts));
        }
    

    At this point, the app is working ok and displaying the posts.

    So i added on my view the next code:

    @foreach($posts as $post)
        @foreach($post->like as $like)
            {{ $like->user->username }}
        @endforeach
    @endforeach
    

    and i got:

    Trying to get property of non-object
    

    I added dd to see what is going on and i got the username (only one of course):

    angelzgr
    

    Regards

    angelz.gutierrez left a reply on Can't Get Relationship • 7 months ago

    Yes, it is working fine. How could i get the whole data ( many post with many likes from many users).

    If it is possible i believe i would have to loop it on blade maybe, not quite sure how could this be done.

    angelz.gutierrez left a reply on Can't Get Relationship • 7 months ago

    Hi,

      #relations: array:1 [▼
        "likes" => Collection {#483 ▼
          #items: array:7 [▼
            0 => Like {#580 ▼
              #softDelete: true
              #fillable: array:5 [▶]
              #connection: null
              #table: null
              #primaryKey: "id"
              #keyType: "int"
              #perPage: 15
              +incrementing: true
              +timestamps: true
              #attributes: array:8 [▶]
              #original: array:8 [▶]
              #relations: array:1 [▶]
              #hidden: []
              #visible: []
              #appends: []
              #guarded: array:1 [▶]
              #dates: []
              #dateFormat: null
              #casts: []
              #touches: []
              #observables: []
              #with: []
              #morphClass: null
              +exists: true
              +wasRecentlyCreated: false
              #forceDeleting: false
            }
            1 => Like {#581 ▶}
            2 => Like {#582 ▶}
            3 => Like {#583 ▶}
            4 => Like {#592 ▶}
            5 => Like {#637 ▶}
            6 => Like {#639 ▶}
          ]
        }
      ]
    

    angelz.gutierrez left a reply on Can't Get Relationship • 7 months ago

    Here it goes:

    Post {#397 ▼
      #fillable: array:12 [▶]
      #connection: null
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      #perPage: 15
      +incrementing: true
      +timestamps: true
      #attributes: array:14 [▶]
      #original: array:14 [▶]
      #relations: array:1 [▶]
      #hidden: []
      #visible: []
      #appends: []
      #guarded: array:1 [▶]
      #dates: []
      #dateFormat: null
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
      +wasRecentlyCreated: false
      #forceDeleting: false
    }
    

    angelz.gutierrez left a reply on Can't Get Relationship • 7 months ago

    Hello,

    Here is the output for the first code:

    Collection {#544 ▼
      #items: array:76 [▼
        0 => Post {#397 ▼
          #fillable: array:12 [▶]
          #connection: null
          #table: null
          #primaryKey: "id"
          #keyType: "int"
          #perPage: 15
          +incrementing: true
          +timestamps: true
          #attributes: array:14 [▶]
          #original: array:14 [▶]
          #relations: array:1 [▶]
          #hidden: []
          #visible: []
          #appends: []
          #guarded: array:1 [▶]
          #dates: []
          #dateFormat: null
          #casts: []
          #touches: []
          #observables: []
          #with: []
          #morphClass: null
          +exists: true
          +wasRecentlyCreated: false
          #forceDeleting: false
        }
        1 => Post {#398 ▶}
        2 => Post {#399 ▶}
        3 => Post {#400 ▶}
        4 => Post {#401 ▶}
        5 => Post {#402 ▶}
        6 => Post {#403 ▶}
        7 => Post {#404 ▶}
        8 => Post {#405 ▶}
        9 => Post {#406 ▶}
        ...
    

    It seems it does return the likes for each post.

    I also tried your second approach:

    Trying to get property of non-object
    

    The first works ok, but will i be able to obtain posts, likes, and users ???

    Regards

    angelz.gutierrez left a reply on Can't Get Relationship • 7 months ago

    Actually it is really funny because if i do a dump i get the first username!

    Regards

    angelz.gutierrez started a new conversation Can't Get Relationship • 7 months ago

    Hello,

    I'm trying to get an object with several relationships (Post->likes->user->username), here is an example of my initial relationship:

    Post class

    class Post extends Model implements Transformable
    {
        use TransformableTrait, SoftDeletes;
    
        protected $fillable = [
            'user_id', 'group_id', 'message', 'external_data', 'deleted_at', 
            'place', 'lat', 'lng', 'comments_count', 'share_count', 'likes_count',
            'wall_user_id'
        ];
    
    
        public function user()
        {
            return $this->belongsTo('App\Entities\User')->where('is_blocked', '=', 0);
        }
    
        public function like()
        {
            return $this->hasMany('App\Entities\Like');
        }
    }
    

    Likes class:

    class Like extends Model implements Transformable
    {
        use TransformableTrait, SoftDeletes;
    
        protected $softDelete = true;
    
        protected $fillable = ['post_id', 'user_id', 'type', 'deleted_at', 'update_id'];    
    
        public function user()
        {
            return $this->belongsTo('App\Entities\User')->where('is_blocked', '=', 0);
        }
    }
    

    And finally, the User class:

    
    class User extends Authenticatable implements Transformable
    {
        use TransformableTrait;
    
        protected $fillable = [
            'name', 'email', 'password', 'username', 'email_verification_token', 'email_token_created', 'is_email_verified', 'is_blocked', 'is_active', 'source', 'social_data', 'cover_photo_position', 'last_login'
        ];
    
        protected $hidden = [
            'password', 'remember_token',
        ];
    
        public function like(){
            return $this->hasMany(Like::class);
        }
    
        //----------------------------------------------------------
    
    }
    

    I return all the rows to my view using:

            $posts = Post::orderBy('id', 'desc')->get();
            return view('frontend.home.home', compact('posts', $posts));
    

    and also tried with

            $posts = Post::all();
            return view('frontend.home.home', compact('posts', $posts));
    

    So, everytime i try to get the user on my blade using:

    @foreach($posts as $post)
        {{ $post->like->user->username }}
    @endforeach 
    

    also tried with:

        @foreach($post->like as $likes)
            {{ $likes->username }}
        @endforeach
    

    I get the error:

    Undefined property: Illuminate\Database\Eloquent\Collection::$user
    

    Any idea what could be happening ??? I don't know what else i could do to get that relationship working.

    Thanks in advanced

    Edit Your Profile
    Update

    Want to change your profile photo? We pull from gravatar.com.