untymage

untymage

Member Since 8 Months Ago

Experience Points 1,160
Experience Level 1

3,840 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 Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

13 Jun
6 days ago

untymage started a new conversation Phpunit Returns Green On Null

I'm trying to make sure my model have a path ( with a slug) but i dont even have a slug column on my table but it returns green:


public function a_thread_has_a_path()
{
    
    $thread = factory(Thread::class)->create();

    $this->assertEquals("/thread/{$thread->id}/{$thread->slug}", $thread->path());
}
11 Jun
1 week ago

untymage left a reply on Grouping By Pivot Table Columns

@kevinbui thanks for the reply, But it gave me a unnamed key on the collection:

Collection {#511 ▼
  #items: array:1 [▼
    "" => Collection {#520 ▶}
  ]
}
10 Jun
1 week ago

untymage started a new conversation Grouping By Pivot Colum

Have this collection (on $thread->tags) :

Collection {#520 ▼
  #items: array:2 [▼
    0 => Tag {#505 ▼
      #relations: array:1 [▼
        "pivot" => Pivot {#506 ▼
          #attributes: array:3 [▼
            "thread_id" => 1
            "tag_id" => 1
            "tag_type" => "main"
    1 => Tag {#505 ▼
      #relations: array:1 [▼
        "pivot" => Pivot {#506 ▼
          #attributes: array:3 [▼
            "thread_id" => 1
            "tag_id" => 1
            "tag_type" => "custom"
  ]
}

and how do i group this colletion by tag_typein the pivot table ? it should be something like this one :

Collection {#490 ▼
  #items: array:2 [▼
    "main" => Collection {#489 ▼
      #items: array:1 [▼
        0 => Tag {#493 ▶}
    1 => Tag {#493 ▶}
      ]
    },
   "custom" => Collection {#489 ▼
      #items: array:1 [▼
        0 => Tag {#493 ▶}
  ]
}
$tagTypes = $thread->tags->filter->pivot->groupBy('tag_type');

which is doesnt work and gave me a unnamed key in array:

Collection {#511 ▼
  #items: array:1 [▼
    "" => Collection {#520 ▶}
  ]
}

any idea?

08 Jun
1 week ago

untymage started a new conversation Update Column Based On Number Of Record? (Seeding)

How to update all tag_id in this column:

artist_id | tag_id 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3

to

artist_id | tag_id 1 1 1 2 1 3 2 4 2 5 2 6 3 7 3 8 3 9

I tried this :

for ($i=1;$i <9; $i++){
    DB::table('artist_tag')->update(['tag_id' => $i]);
}

but didnt work.

07 Jun
1 week ago

untymage started a new conversation Prevent Factory To Persist Extra Data For Has

Hello folks, I have two model Thread and Reply, The goal is generate some fake data to they tables, 60 Threads with 10 Replys for each of them:

ReplyFactroy.php

$factory->define(Tag::class, function (Faker $faker) {
    return [
        'thread_id'   => factory('App\Thread'),
        'name'         =>  $faker->word,
    ];
});

Seeder:

        $threads = factory('App\Thread', 60)->create();

        $threads->each(function ($thread){
            factory('App\Tag')->create(['thread_id'=> $thread->id]);
        });

The code above will generate 600 thread row with 60 tags which is not what i want, it would be 60 threads with 60 tags.

is there anyway to stop factory for duplication on thread factory ?

I know we can handle this manually with specific number but is there another way ?

06 Jun
1 week ago

untymage started a new conversation Stop The Loop From Repeating Categories

I'd want show categories if their exist on the model looks like this:

  • Albums -album 1 -album 2
  • Singles (if there is no items for this category it shouldnt display on the page at all)

my code :

@foreach($artist->albums as $album)
    
    <div>Albums</div>

    {{$album->title}} - {{$album->year}}

@endforeach

it will render multiple categories:

  • Albums -album 1 -Albums -album 2

if i take the "Albums" element outside of loop then it shows categories no matters if they have items or not

05 Jun
2 weeks ago

untymage left a reply on Str::slug Capitalize After Dash

@WIZJO - Sorry i edited my question, I was looking for capitalizing letters after dash but the ucfirst method only capitalize the first letter if the string has dash between.

I found the solution but in hard way:

public function setSlugAttribute($value) { $str = implode('-', array_map('ucfirst', explode('-', Str::slug($value))));

return $this->attributes['slug'] = ucwords($str);

}

untymage started a new conversation Str::slug With Uppercase First Letter

I'm trying to Uppercase the first letter of slugs with Mutator but it wont work :

public function setSlugAttribute($value)
{
    return $this->attributes['slug'] = Str::slug(ucfirst($value));
}

untymage left a reply on Two Range Of Number For Data Seeding

@johnbraun thanks! That's exactly what I wanted, @davidpetrov, I know there is a attach method but for some reason i needed a specific range of numbers.

untymage started a new conversation Two Range Of Number For Data Seeding

I want to seed my pivot table like this :

    DB::table('tag_thread')->insert([
        ['tag_id' => 51, 'thread_id' => 1],
        ['tag_id' => 52, 'thread_id' => 2],
        ['tag_id' => 53, 'thread_id' => 3],
        ['tag_id' => 54, 'thread_id' => 4],
        ['tag_id' => 55, 'thread_id' => 5],
        ['tag_id' => 56, 'thread_id' => 6],
        ['tag_id' => 57, 'thread_id' => 7],
        ['tag_id' => 58, 'thread_id' => 8],
    ['tag_id' => 59, 'thread_id' => 9],
    ['tag_id' => 60, 'thread_id' => 10],
    ]);

is there another good approach for this kind of seeding ? there is two range of number 50-60 and 1-10

untymage started a new conversation Sharing Variable With Closure ?

I have this variable in my controller :

public function show(Thread $thread)
{
    $mainTags = $thread->tags->filter(function ($tag){

        return $tag->type == 'main';

    })->values();

return view('thread.show', compact('mainTags'));

So how to share $mainTags in all views ? with View Composer it didnt work for me :

    view()->share('mainTags', function (Thread $thread){

        $thread->tags->filter(function ($tag){

        return $tag->type == 'main';

        })->values();
    });
03 Jun
2 weeks ago

untymage started a new conversation Is It Safe To Use Double !! !! Only For Fetching Data From Server?

I wrote a unit test for my project that checks if the title exist on my page:

$tag = factory(Tag::class)->create(['name' => 'Example & Example ']);
$this->get($release->path())->assertOk()->assertSee($tag->title);

But since the laravel escapes data with {{ }} my test fails and says :

Failed asserting that page contains "Example & Example".

Because laravel convet & to of :

<a href="#">Akbar &amp; # farid  }}</a>

So what is good approach to handle this test ? is it safe to only use {{!! !!}} for only getting data from database ?

01 Jun
2 weeks ago

untymage left a reply on Unable To Testing Many To Many Relationship Assertion Failed

I found the problem that i forgot about pivot table :

public function it_belongs_to_many_tags()
{
    $tag = factory(Tag::class)->create();
    $thread = factory(Thread::class)->create();

    DB::table('tag_thread')->insert([
       'tag_id' => $tag->id,
       'thread_id' => $thread->id
    ]);

    $this->assertInstanceOf(Tag::class, $thread->tags[0]);

}

untymage left a reply on Laravel Issue: Unable To Testing Many To Many Relationship Assertion Failed

@TRAY2 - Yes you're right, But Jeffrey tests relationships with "assertInstanceOf" method and it not work on many to many relationships.

untymage started a new conversation Laravel Issue: Unable To Testing Many To Many Relationship Assertion Failed

Has anyone tried 'assertInstanceOf' method on Many-to-Many Relationship?After a day, I could not solve the problem after a day of search :

Failed asserting that Illuminate\Database\Eloquent\Collection Object (...) is an instance of class "App\Tag".

I made a separate project to tackle this problem. But seriously i have no clue , All of my codes :

Feature\Thread.php

namespace Tests\Unit;

use App\Tag;
use App\Thread;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ThreadTest extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function it_belongs_to_many_tags()
    {

        $thread = factory(Thread::class)->create();

        $this->assertInstanceOf(Tag::class, $thread->tags);

    }

}

2019_06_01_114457_create_threads_table.php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateThreadsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('threads', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->text('body');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('threads');
    }
}

2019_06_01_114508_create_tags_table.php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTagsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tags', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('tags');
    }
}

pivot table (2019_06_01_114720_create_tag_thread_table.php)


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTagThreadTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tag_thread', function (Blueprint $table) {
            $table->primary(['tag_id','thread_id']);
            $table->unsignedBigInteger('tag_id');
            $table->unsignedBigInteger('thread_id');

            $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
            $table->foreign('thread_id')->references('id')->on('threads')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('tag_thread');
    }
}

Thread.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    public function tags()
    {
        return $this->belongsToMany(Tag::class);
    }
}

Tag.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Tag extends Model
{
    public function threads()
    {
        return $this->belongsToMany(Tag::class);
    }
}

Note that the code alone will work but its test not.

31 May
2 weeks ago

untymage started a new conversation Unit Test For Many To Many Relationship

I'm trying to make sure that my many to many relationship will actually work but what is this error mean?

Failed asserting that Illuminate\Database\Eloquent\Collection Object (...) is an instance of class "App\Role".

My unit test:

$role = factory('App\Role')->create();

$this->assertInstanceOf(User::class, $role->users);

Models:

User

public function roles()
{
    return $this->belongsToMany(Role::class);
}

Role

Role

public function users()
{
    return $this->belongsToMany(Users::class);
}

my pivot table:

        $table->primary(['role_id', 'user_id']);
        $table->unsignedBigInteger('role_id');
        $table->unsignedBigInteger('user_id');
        $table->timestamps();

        $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
17 May
1 month ago

untymage started a new conversation What Is The Best Approach For Data Visibility Restriction? (guest,members,subscribers)

Hello everyone, First of all i have these tables in my database: Artists, Albums, RecordLabels, Playlists, The goal is to hide some contents between "guest,members,subscribers", How do i do that ? Should i add this column to every tables that i have ?

$table->enum('visible', ['guest', 'member', 'subscribers'])->default('guest');
14 May
1 month ago

untymage left a reply on Why Are My Tests Is Slower Than Jeffrey's Tests?

@DIEGOAURINO - Yeah, It sounds like the problem was "shared folder", So when we doing TDD we shouldn't initial laravel project in share folder right ?

untymage started a new conversation Why Are My Tests Slower Than Jeffrey's Tests?

OS : Windows 10 Hardware: i7 - 6700k, SSD 850 EVO - 16Gig RAM ENV : Vagrant / PHPStorm

Hello everyone, I'm just wondering at why my tests are slow? Despite the fact that Jeffrey tests with 40 tests and 80 assertion are done less than 1 seconds (500ms) , But the default laravel test with 1 assertion in my side It takes more than 1 second ? :

Time: 1.63 seconds, Memory: 22.00 MB

OK (1 test, 1 assertion)

Even though I use the sqlite in memory it doesn't have a big impact. Any ideas?

25 Mar
2 months ago

untymage started a new conversation When To Use Vue Instead Of Laravel ?

Hello everyone, I'm new in coding and sorry about my thread title, But i'm confused a little bit, I'm just wondering When to use Vue instead of Laravel ? for example we could use @foreach in laravel blade to iterate our data and the other hand there is a v-for for this action in Vue , So when we should Vue instead of Laravel ?

26 Nov
6 months ago

untymage left a reply on Get Actual Clinet IP Adress

@BOBBYBOUWMANN - Thanks, I'm bit a confused about some stackoverflaw topics actullay https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php

So i went here for some tips xD But all of this methods only return my proxy ip, seems impossible to that.

untymage started a new conversation Get Actual Clinet IP Adress

is there anyway to get actual client IP address of they are using proxies ?

16 Nov
7 months ago
18 Oct
8 months ago

untymage left a reply on What Is The Meaning Of Laravel To Use The Word "Channels"?

You can say in a sentence please

untymage started a new conversation What Is The Meaning Of Laravel To Use The Word "Channels"?

I'd like to know meaning of this word "Channels" in Laravel world, I just heard it at Youtube.

16 Oct
8 months ago

untymage left a reply on Question About Php Artisan Make:controller --resource

I know this guys, just wondering about what did laravel in background for registering route paths... (Where are the route paths stored, i know there is route:list)

untymage started a new conversation Question About Php Artisan Make:controller --resource

Excusme me, Where laravel puts route paths ? i mean, when we generate resource controller with artisan command, how we do access to route URIs ? (ex: Route::get('/', [email protected]);

11 Oct
8 months ago

untymage left a reply on Advice For Relationship Between Album And Artist (music Stuff)

@cmdobueno Thanks, I will work on it, it's going very hard to me cuze the other side there is Track and Label Table, a Album hasmany tracks and a Label hasmany albums xD

untymage left a reply on Advice For Relationship Between Album And Artist (music Stuff)

@Tray2 if "Artist has many albums Album has many artists"

Should I do this?

$this->belongToMany(Artist::class);

and

$this->belongToMany(Album::class);

?

untymage started a new conversation Advice For Relationship Between Album And Artist (music Stuff)

an album may have many Artists like this release :

https://open.spotify.com/playlist/4tnlurVAZXe5L5bFvR4mQg

but the other hand a album may have only one artist like:

https://open.spotify.com/album/4TU8d9DGafZZiyN7peC4sl

I'd little confused about relationships, may i use belongToMany: Artist or BelongTo: Artist ?

10 Oct
8 months ago

untymage left a reply on Seeder Creator Option For Make:model

I know this , I'm looking for a quicker way like this:

php artisan make:model Post -mcrfs

s for seeder

untymage started a new conversation Seeder Creator Option For Make:model

Is there a purpose for not having a Seeder creator option? like:

php artisan make:model Post -mcrfs