untymage

untymage

Member Since 10 Months Ago

Experience Points 2,650
Experience Level 1

2,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 0
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.

21 Aug
7 hours ago

untymage left a reply on Laravel Brand Redesign: Live Now On The Official Website!

Wish we could use the old design too.

19 Aug
2 days ago

untymage started a new conversation Different Default Value For Specific Model In Polymorphic Many To Many Relationship

I have a extra column on my pivot table usage :

tag_id | taggable_id | taggable_type | usage

In migration i setup default value for usage to 0, But what if another models doesnt need a usage column?

Is it possible to set null for specific model instead of 0 if so How?

14 Aug
1 week ago

untymage left a reply on Extra Field On Pivot Table Not Affected When Using MorphMap

Yeah it'll works properly when i comment morphMap out, Really Dont know what's wrong here

untymage started a new conversation Extra Field On Pivot Table Not Affected When Using MorphMap

So i have morph many-to-many relation and have a extra field on it :

tag_id | taggable_id | taggable_type | usage

When i use morphMap the column usage not working which is increments number by every record


    public function boot()
    {

        Relation::morphMap([
            'Thread' => 'App\Thread',
        ]);


    }

any idea?

13 Aug
1 week ago

untymage left a reply on Attach And Increment

@fNope, I'm Talking about increment when we do attach to another model your link just about incrementing pivot table

untymage started a new conversation Image Model, Multiple Relationship

How would you guys set up relationship between , Image => User, Thread, Video?

All of Model may have many images or covers , Should i just create table for each model ArtistsPhotos, AlbumCovers and set a hasMany relationship ... ? what is your suggestion?

untymage started a new conversation Attach And Increment

I have a pivot table with these column :

tag_id | thread_id | usage

For every attachment i wanna increment usage column, I do this way :


$thread->tags()->attach($tag);

\DB::table('tag_thread')->where(['thread_id' => $thread->id, 'tag_id' => $tag->id)->increment('usage');

But is there better way ? I'm thinking about pass another argument to attach method but dont know how:

$thread->tags()->attach($tag, ['usage'  => ???? ] );

12 Aug
1 week ago

untymage started a new conversation Assert Redirect For All Routes That Have Specific Prefix

is there a method that asserting group of routes that have specific prefix? for example:


$this->get('admin/index')->assertRedirect();

$this->get('admin/create')->assertRedirect();

$this->get('admin/edit')->assertRedirect();

I wanna assert redirect to all routes that started with admin prefix in one assertion.

09 Aug
1 week ago

untymage started a new conversation (Validation) The Given Data Was Invalid

I'm using one validation for both create and update page:

Create page http incoming array :

array:2 [
  "title" => "Some TItle"
  "body" => "some Body"
]

Update page http incoming array :

array:1 [
  "data" => array:2 [
      "title" => "Some TItle"
      "body" => "some Body"
]
    

So i added data prefix if http request is from update page, it works on create page, But i getting error Illuminate\Validation\ValidationException : The given data was invalid. for update page any ideas?

07 Aug
2 weeks ago

untymage started a new conversation Model::create VS Model:insert (Number Of Query)

When to use insert method instead of create ? in this example the insert perform only one query for 3 tags :


$inputField = 'tag1,tag2,tag3';

$tags = explode(',', $inputField);

$data = collect($tags)->map(function ($tag){
    return ['name' => $tag];
})->toArray();

Tag::insert($data);

// 1 query


create 3 query


$inputField = 'tag1,tag2,tag3';

$tags = explode(',', $inputField);

foreach ($tags as $name) {
    Tag::create(compact('name'));
}

// 3 query


So if insert method performs 1 query why most of videos in laracasts uses create in foreach loop?

27 Jul
3 weeks ago

untymage started a new conversation Ignore Accessor On Vue

is it possible to ignore accessors on vue ?

I'm converting milliseconds to human readable time and i wanna ignore accessors when i try to update the form.


    public function getLengthAttribute($value)
    {

        return $this->attributes['length'] = gmdate("i:s", $value);
    }

26 Jul
3 weeks ago

untymage left a reply on [Vue Warn]: Unknown Custom Element: <router-view>

Problem was asset('admin.js') which should be '/js/admin.js'

untymage left a reply on [Vue Warn]: Unknown Custom Element: <router-view>

isn't <router-view> built in Vue component?

untymage started a new conversation [Vue Warn]: Unknown Custom Element: <router-view>

Any idea why i'm getting this error?:

admin.js:4555 [Vue warn]: Unknown custom element: <router-view> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

(found in <Root>)

admin.js:


import Vue from 'vue';
import axios from 'axios';
import VueRouter from 'vue-router';
import routes from './routes';


Vue.use(VueRouter);


let app = new Vue({
    el: '#app',
    router: new VueRouter(routes),
});

routes.js :


import Create from './components/admin/form/Create';


export default {

    mode: 'history',

    routes: [
        {
            path: '/admin/create',
            component: Create
        }
    ],
}


master.blade.php:


<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Create</title>
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>

<div id="app">
    <router-view></router-view>
</div>

<script src="{{ asset('admin.js') }}"></script>


</body>
</html>


25 Jul
3 weeks ago

untymage started a new conversation One Component For Edit/Create Pages

Edit: My question in totally wrong sorry!

Can you guys give me an idea of how to make one component for Edit/Create in Laravel/Vue ? is it possible at all or we should just create two separate component ?

22 Jul
4 weeks ago

untymage started a new conversation HTML Name Attribute Vs Vue V-model

When to use html name attribute along side of vue v-model for form submitting? I see some people just use v-model without name attribute for submit the form so, What is different between these ?

20 Jul
1 month ago

untymage started a new conversation Where To Put Admin Assets?

I wanna hide my admin assets from the guests routes, Where would you put these? is it ok to put this thing to/public folder ?

14 Jul
1 month ago

untymage started a new conversation Append Number To Duplicated Keys When Combining Two Array

I wanna combine this two array as key value pairs, as we cannot have duplicated keys in one array array_combine removes duplicated keys in array

$array1 = [
    'a',
    'a',
    'b'
];

$array2 = [
    'apple',
    'red',
    'blue'
];

$combinedArray = array_combine($array1, $array2);


So the question is how do i append number automatically to duplicated keys?

combinedArray => [

    [a1] => 'apple',
    [a2] => 'red',
    [b] => 'blue'

]

13 Jul
1 month ago

untymage left a reply on How To Get Blade File Path?

@mstrauss it helps but it's not clean, if i wanna check two or more path it became something like this :


@if(strpos(request()->path(), 'path1') !== false || strpos(request()->path(), 'path2') !== false)
               //do something
@endif

untymage started a new conversation Pass Array Of Inputs To $request Variable

We can pass array of inputs to request helper :


request(['title','body']);

How do i pass array of input like above to $request variable when Request object was type hinted ? :


public function store(Request $request) {

    $request-> ?? 

}

12 Jul
1 month ago

untymage left a reply on Using FirstOrCreate On Relationship Cause Error

@sergiu17 i tried these:

public function addTag($name)
{

    $tag =  $this->tags()->firstOrCreate(['name' => $name]);

    if ( ! $this->tags()->where('tag_id', $tag->id)->exists()) {
        $tag->threads()->attach($this->id);
    }


}

But it fail again :

Integrity constraint violation: 19 UNIQUE constraint failed: tags.name

I dont understand one thing, Why when i use firstOrCreate it try to save given value to database even it's duplicated?

untymage left a reply on Using FirstOrCreate On Relationship Cause Error

@sergiu17 What's the solution? i used firstOrCreate to say: if you find the record dont persist to database and just attach it

untymage started a new conversation Using FirstOrCreate On Relationship Cause Error

Say i have many-to-many relationship with Thread and Tag

Thread.php

When i try to use $this->tags()->firstOrCreate :

public function addTags($name)
{
        $tag = $this->tags()->firstOrCreate(compact('name'));

        $this->tags()->attach($tag->id);

}

it cuase error:

SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: thread_tag.thread_id, thread_tag.tag_id (SQL: insert into "thread_tag" ("thread_id", "tag_id") values (1, 1))

untymage started a new conversation Can't Import Slug To Database When Attribute Have Special Characters

I have set up this mutator in my model :

public function setSlugAttribute($value)
{

    return $this->attributes['slug'] = ucwords(Str::slug($value), '-');

}

When the attribute have special character it prevent to persist the value to the database, For example if the value equal to this : & % test valie $ mutator will ignore and replace it with white space i think ...

11 Jul
1 month ago

untymage left a reply on How To Get Blade File Path?

@aurawindsurfing imagine i have 2 blade file with 1 parital blade file:

i want this:

partial.blade.php :

@if ( if current blade file is x )
    do this
@endif

@if ( if current blade file is y )
    do this
@endif

untymage started a new conversation How To Get Blade File Path?

I have a partial blade file, I want to tell it if you included to specific blade file do something else, I need to find out existing blade file path to do that, i did this:

{{view()->getPath()}} but it cause error :

Method Illuminate\View\Factory::getPath does not exist

09 Jul
1 month ago

untymage left a reply on Composer "suggests Installing"

@bobbybouwmann Just curious how to find packages that it suggested ? i googled ext-com_dotnet and nothing..

untymage started a new conversation Composer "suggests Installing"

I tried to install getid3 through composer but it shows some notices:

Installing james-heinrich/getid3 (v1.9.17): Downloading (100%)

james-heinrich/getid3 suggests installing ext-com_dotnet (COM extension is required when loading files larger than 2GB on Windows.)

james-heinrich/getid3 suggests installing ext-dba (DBA extension is required to use the DBA database as a cache storage.)

james-heinrich/getid3 suggests installing ext-mysql (MySQL extension is required to use the MySQL database as a cache storage (deprecated in PHP 5.5, removed in PHP >= 7.0, use `ext-mysqli` instead).)

james-heinrich/getid3 suggests installing ext-rar (RAR extension is required for RAR archive module.)

james-heinrich/getid3 suggests installing ext-SimpleXML (SimpleXML extension is required to analyze RIFF/WAV/BWF audio files (also requires `ext-libxml`).)

james-heinrich/getid3 suggests installing ext-sqlite3 (SQLite3 extension is required to use the SQLite3 database as a cache storage.)

Does this mean the package will not work correctly ? How do i install packages that mentioned above? for example where is ext-com_dotnet ?

08 Jul
1 month ago

untymage started a new conversation Return Two Or More Result From Pivot Table

What is the shorten version of this :

$this->models->filter(function ($model) {
    return $model->pivot->pivotcolumn == 'one' or 
    $model->pivot->pivotcolumn == 'two';
})->values();

it will work but what if i want filter through over three or more pivot table ? When i using return $model->pivot->pivotcolumn == 'one' or 'two' it return all result and wouldnt filter it.

04 Jul
1 month ago

untymage left a reply on Automatic Increment Colum By Creating Model Instance

I found the solution (i think), the name of tags is the same , if it's new then it should create new tag, here is what i wanted but i'm not sure is it cleaner way or not:

Thread.php:

public function addTags($tags)
{
    $attribute = explode(',', $tags);

    foreach ($attribute as $name) {

        $tag = Tag::firstOrCreate(compact('name'));

        $this->tags()->syncWithoutDetaching([$tag->id]);

        $tag->increment('uses');

    }

    return;

}

untymage left a reply on Automatic Increment Colum By Creating Model Instance

@snapey Sorry about the explanation, Imagine "php" tag used in 10 thread i wanna set 10 to uses column but have no idea how to do it.

untymage started a new conversation Automatic Increment Colum By Creating Model Instance

I have a tag table with 3 column:

id     |name      |uses
-------|----------|--------
     1  |     php |      1

How do i increment uses column by every model instance ?

Thrad.php

public function addTag($tags)
{
    return $this->tags()->create(['name' => 'php', 'uses' => ??]);
}

untymage left a reply on Create Or Attach

@mironmg Good to know thanks!

untymage started a new conversation Create Or Attach

I have Many to many relationship with Tag and Thread Model, Here is what i tried for creating or attaching :

Tag.php:

public static function searchByName($name)
{
    return self::where('name', $name)->get()->first();
}

Thread.php :


public function addTags($tags)
{
    $attributes = explode(',', $tags);

    foreach ($attributes as $name) {

        if ( $tag = Tag::searchByName($name) ) {

            $this->tags()->attach($tag->id);

            continue;
        }

        $this->tags()->create(compact('name'));
    }

    return;

}

I set up a static method in Tag model for checking tag by name (searchByName) if the tag exist then only attach to the new Thread otherwise create a new tag, I think this approach is not clean , because for every many to many relationship i do this way (creating seach method in model and ...)

So how do you refactor above code?

03 Jul
1 month ago

untymage left a reply on Increment Attribute Value By Vue

Any idea? I'm thinking about using regex to resolve this but the new issue is , it just increamnet 0 to 1 and after that just stick in 1 :

new Vue({
  el: "#app",
  data: {
        inputs: [
        {value: ''},
    ],
    field: "tag[0]",
  },
  methods: {
        addInput() {
        this.inputs.push({value: ''});
        let num = this.field.search(/tag\[(\d)\]/i);
      num++;
      this.field = "tag[" + num + "]";
      
    }
  }
})

current:

<input type="text" name="tag[1]">
<input type="text" name="tag[1]">
<input type="text" name="tag[1]">

expect:

<input type="text" name="tag[0]">
<input type="text" name="tag[1]" >
<input type="text" name="tag[2]">
...

untymage started a new conversation Increment Attribute Value By Vue

With vue , How to increment attributes values ?

<input name="tag[0]">

I wanna increment tag[0] number by user click and also add another input field , Here is what i tried but not working... https://jsfiddle.net/untymage/u4953exs/19/

untymage started a new conversation How To Wrap Up Multilpe Input Fileds Into One Associative Arrays ?

Imagine i'd want to create tracklist and having this inputs :

Form:

<div>
  <input type="text" name="order[]">
  <input type="text" name="titles[]">
  <input type="text" name="duration[]">
  <input type="text" name="artists[]">
</div>

And my question is how to grab all information about songs field into one associative array ? in the above approach when i dump all request into page it shows fields in separated array :

array:7 [▼
  "artists" => array:1 [▶]
  "titles" => array:1 [▶]
  "duration" => array:1 [▶]
  "order" => array:1 [▶]
]

So how do i make my form to show me requests like this :

        "tracks" => [
            0 => [
                'order' => 1,
                'artists' => 'Justin Bieber',
                'duration' => 300,
                'title' => 'Blah'
            ],
            1 => [
                'order' => 2,
                'artists' => 'Justin Bieber',
                'duration' => 400,
                'title' => 'Blah2'
            ],
        ];

What is your approach to handle this form ?

29 Jun
1 month ago

untymage left a reply on How To Register Specific Route File?

@SNAPEY Oh i did not, completely forgot about this thanks!

untymage started a new conversation How To Register Specific Route File?

In RouteServiceProvider i add a method for my route file for admin section :

    protected function mapAdminRoutes()
    {
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/admin.php'));
    }

routes/admin.php

Route::post('admin/threads', '[email protected]');

But i'm getting NotFoundHttpException any idea?

22 Jun
1 month ago

untymage started a new conversation Where To Find All Built In Classes In PHP

The php website itself just have page that shows a few built in classes: https://www.php.net/manual/en/reserved.interfaces.php or https://www.php.net/manual/en/reserved.classes.php

But I'm sure there is a lot of classes that exist but they are not in the above links, For example ReflectionClass has it own page.

So is there a place to able see all built in classes (or interfaces) ?

13 Jun
2 months 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
2 months 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:

edit: it actually worked ! thanks again.

10 Jun
2 months ago

untymage started a new conversation Grouping By Pivot Table Columns

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 ? result should be something like this one :

Collection {#490 ▼
  #items: array:2 [▼
    "main" => Collection {#489 ▼
      #items: array:1 [▼
        0 => Tag {#493 ▶}
       1 => Tag {#494 ▶}
      ]
    },
   "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
2 months 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 | song_id

1 1

1 2

1 3

2 1

2 2

2 3

3 1

3 2

3 3

to

artist_id | song_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(['song_id' => $i]);
}

but didnt work.

07 Jun
2 months ago

untymage started a new conversation Prevent Factory Duplication For Models Relationships

Sorry, I'm stupid. wrong question at all.

06 Jun
2 months 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)
@foreach($artist->albums as $album)
    
    @if($album->type=='Album')
    <div>Albums</div>
    @endif()

    @if($album->type=='Single')
    <div>Single</div>
    @endif()

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

@endforeach

it will render multiple categories:

  • Albums
    • album 1
  • Albums
    • album 1
  • Singles
    • single1
  • Singles
    • single1

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

Excepted:

  • Album
    • album 1
    • album 2
  • Single
    • single 1
    • single 2

if Single havent item then:

  • Album
    • album 1
    • album 2