Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

CrazyVito11

CrazyVito11

Member Since 3 Months Ago

Experience Points
120
Total
Experience

4,880 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
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 1
120 XP
Aug
18
3 months ago
Activity icon

Replied to Get BelongsTo Item Value Only, Not As Object

Finally got the time to give it a shot and I got it to work.

my migration:

Schema::create('tags', function (Blueprint $table) {
    $table->bigIncrements('tag_id');
    $table->unsignedBigInteger('image_id');
    $table->string('tag_string');
    $table->timestamps();

    $table->foreign('image_id')
        ->references('id')->on('images');
});

I added this to the Image model

    public function allTags()
    {
        return $this->hasMany('App\Tags');
    }

Thanks!

Aug
13
3 months ago
Activity icon

Replied to Get BelongsTo Item Value Only, Not As Object

yeah users can add new tags, the idea is that if they try to use a tag that doesn't exist yet, it'll get created when they upload the image.

I'll give it a shot!

Aug
10
3 months ago
Activity icon

Replied to Get BelongsTo Item Value Only, Not As Object

@snapey so in short, image_tags will store the tag as a string, and if the tag hasn't been found inside the tags table, add it there as well so I can use that to filter on tags?

Aug
07
3 months ago
Activity icon

Replied to Get BelongsTo Item Value Only, Not As Object

@snapey so you mean create a table that only stores the tags? and using that table create the autofill feature?

Activity icon

Replied to Get BelongsTo Item Value Only, Not As Object

@silencebringer when I did that, I no longer got any errors, but sadly now it just returns a empty array :/ There are items inside the db so I don't really know what is wrong (I'm still new to pivot tables and such)

Aug
05
3 months ago
Activity icon

Replied to Get BelongsTo Item Value Only, Not As Object

@snapey I could do that, but the reason as to why I want to store the tags in another table is so I can reuse them, and I'm planning on creating a autofill option for tags, so I think it is easier to create then and less processor intensive for the SQL server. Or is that not the case?

Activity icon

Replied to Get BelongsTo Item Value Only, Not As Object

@silencebringer sadly I couldn't get that to work, It complains about tags.id not existing :/ Am I missing something?

Aug
03
3 months ago
Activity icon

Started a new Conversation Get BelongsTo Item Value Only, Not As Object

So I have a model that remembers a filename and tags of a image, so you can search through a lot of images easier. Now I have 2 other models (ImageTags and Tags). The reason why I have ImageTags and Tags is so I can reuse tags and autofill them when you upload a new image.

So tags only stores a unique ID and a string that holds the tag. While ImageTags holds a unique ID, the id of the image and the id of the tag that we linked to that image.

I got this to work, but the tag is returned as a object that then has a string inside it with the tag.

My Image model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Image extends Model
{
    protected $table = 'image';

    public function tagsList()
    {
        return $this->hasMany('App\ImageTags');
    }
}

My ImageTags model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class ImageTags extends Model
{
    protected $table = 'image_tags';

    public function tag()
    {
        return $this->belongsTo(Tags::class, 'tag_id', 'tag_id')->select('tag');
    }
}

My Tags model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Tags extends Model
{
    protected $table = 'tags';
}

this is what I get when I call $imageObject->tagsList :

[
  {
    "image_tag_id": 1,
    "image_id": 3,
    "tag_id": 1,
    "created_at": null,
    "updated_at": null,
    "tag": {
      "tag": "example tag 1"
    }
  },
  {
    "image_tag_id": 2,
    "image_id": 3,
    "tag_id": 2,
    "created_at": null,
    "updated_at": null,
    "tag": {
      "tag": "example tag 2"
    }
  }
]

What I want:

[
  {
    "image_tag_id": 1,
    "image_id": 3,
    "tag_id": 1,
    "created_at": null,
    "updated_at": null,
    "tag": "example tag 1"
  },
  {
    "image_tag_id": 2,
    "image_id": 3,
    "tag_id": 2,
    "created_at": null,
    "updated_at": null,
    "tag": "example tag 2"
  }
]

So if I would want to show all the tags in my blade I would have to write something like this:

@foreach($imageObject->tagsList as $tag)
            <div class="col-auto px-2">
                <div class="bg-info text-white p-2">
                    {{ $tag->tag->tag }}
                </div>
            </div>
        @endforeach

I would like to display it like this: {{ $tag->tag }} and not like {{ $tag->tag->tag }}

How can I make this work? I tried to add a pluck in ImageTags but that didn't work.

Thanks!