piljac1

piljac1

Member Since 2 Months Ago

Experience Points
12,300
Total
Experience

2,700 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
15
Lessons
Completed
Best Reply Awards
18
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.

Level 3
12,300 XP
Dec
08
1 day ago
Activity icon

Replied to Illuminate\Database\QueryException...

You can restart your MySQL server and skip grant tables. That way you can reset your root password.

https://www.a2hosting.com/kb/developer-corner/mysql/reset-mysql-root-password

Dec
07
2 days ago
Activity icon

Replied to Google Autocomplete Doesnt Work When Compiled With Mix, Why Is That?

If you need to use your functions outside your bundled JS, you should assign them to the window.

window.initAutocomplete = function() {
    // ...
}

And to use them, prepend window to your already existent calls

window.initAutocomplete()
Activity icon

Replied to Illuminate\Database\QueryException...

Try using DB_PASSWORD with empty quotes.

DB_PASSWORD=""

Else, add a password to your root user. It should solve your issue (already solved mine in the past).

Activity icon

Replied to Update Data Failed

@jlrdw I never used the request helper that way, but I know that you can use it to retrieve a specific subset of keys in your request (like he did).

Looking at the source code, it takes the request collection and only keeps specified keys (preserving the key => value pair).

If his input names are the same as his DB column names, it can work.

Activity icon

Awarded Best Reply on Update Data Failed

You're calling update on a collection instead of a model. You should use first() instead of get() to retrieve a single model instance.

 $offtime = Offtime::where('user_id', $id)->whereYear('year', $year)->first();
Activity icon

Replied to Update Data Failed

You're calling update on a collection instead of a model. You should use first() instead of get() to retrieve a single model instance.

 $offtime = Offtime::where('user_id', $id)->whereYear('year', $year)->first();
Nov
26
1 week ago
Activity icon

Awarded Best Reply on Trying To Get Property 'id' Of Non-object For One User Type

Have you tried to put a dd inside your if($this->filled_id == NULL) condition ? As of now, if this condition is hit in your loop somehow, a string is returned and you'd be trying do get the property id of a string (which is not an object), and it will throw the error you're getting.

Nov
24
2 weeks ago
Activity icon

Replied to How To Combine Two Collections With A Common Key

I don't know what your code base is, but I guess something like that would work (UNTESTED)

// Your final collection
$families = collect();

// The $adults variable here represents your retrieved adults collection
$adults->each(function($adult, $key) use (&$families)) {
    /****** THIS PART COULD BE OPTIMIZED WITH A QUERY BUILDER ******/
    $adults = Adult::where('family_id', $adult->family_id)->get();
    $children = Child::where('family_id', $adult->family_id)->get();
    $family = $adults->merge($children);
    /***************************************************************/

    $families->put($adult->family_id, $family);
});
Nov
23
2 weeks ago
Activity icon

Replied to Could Not Open Input File: Artisan

Are you 100% sure that your console location really is your Laravel project root folder ? Because this error occurs when you're not.

Nov
21
2 weeks ago
Activity icon

Awarded Best Reply on When One Checkbox Is Checked Showing Its Related Checkboxes Using Jquery

I see. There is a lot of work to do and it's kinda hard to do it blindfolded (without testing). But I'll try and give you a heads up later today (gotta go back to bed if I don't want to fall asleep while working).

Btw, just realized that the following

$brand=brands::where("segment_id",$segment) ->pluck('brands.brand_name,brands.brand_id')->all();

Should be (in correct Laravel standards)

$brands = Brand::where('segment_id', $segment)->select('brand_name', 'brand_id')->get();
Nov
20
2 weeks ago
Activity icon

Replied to How To Count Total Of A Column?

Product::where('category', $yourCategory)->sum('price');

Edit : I answered too late, @tisuchi was quicker lol

Nov
19
2 weeks ago
Activity icon

Awarded Best Reply on Sort By Created_at

If you rename your variables/relations correctly like @nakov suggested,

this would show the latest entry (like @goldtaste suggested) :

$ticket->activities->latest()->first();

P.S. The above code is based on the created_at timestamp. If you wish to use another column, you can specify it (here I'm using purchased_at as an example :

$ticket->activities->latest('purchased_at')->first();
Activity icon

Replied to To Seed Or Not To Seed In Writing Tests ?

We personally use factories when applicable (test counts for example). We tend to avoid automated generation in cases were we need to test interactions with models. That way we can easily see what the original data was and what should be expected.

Activity icon

Replied to Sort By Created_at

If you rename your variables/relations correctly like @nakov suggested,

this would show the latest entry (like @goldtaste suggested) :

$ticket->activities->latest()->first();

P.S. The above code is based on the created_at timestamp. If you wish to use another column, you can specify it (here I'm using purchased_at as an example :

$ticket->activities->latest('purchased_at')->first();
Nov
15
3 weeks ago
Activity icon

Replied to The GET Method Is Not Supported For This Route. Supported Methods: POST.

Add a slash to the front of your routes URLs. It will most likely solve your issue (because currently your routes don't start from your website root). If it still doesn't work, let us know !

Route::get('/display','[email protected]');

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

Route::delete('/delete/{Pnumber}','[email protected]');
Activity icon

Replied to The GET Method Is Not Supported For This Route. Supported Methods: POST.

It's hard to help you without a tiny bit of code, but my guess is that you have a form with an action of GET instead of POST. Look it up in your concerned blade file if that's the case.

Nov
14
3 weeks ago
Activity icon

Replied to Dynamic Value Doesn't Seem Like A Valid Parameter For A Relatable Query

Update #2

I'm getting a different "type" of $request objects on both relatableColorscalls

[2019-11-14 16:16:11] local.DEBUG: array (
  'editing' => 'true',
  'editMode' => 'update',
  'viaResource' => NULL,
  'viaResourceId' => NULL,
  'viaRelationship' => NULL,
)  
[2019-11-14 16:16:12] local.DEBUG: array (
  'current' => '2',
  'first' => 'false',
  'search' => NULL,
  'withTrashed' => 'false',
  'resourceId' => '2',
  'viaResource' => NULL,
  'viaResourceId' => NULL,
  'viaRelationship' => NULL,
)  
Activity icon

Replied to Dynamic Value Doesn't Seem Like A Valid Parameter For A Relatable Query

@sinnbeck Thanks for the suggestion. I'll ask the project admin if he wants to upgrade.

As a side note, I pin pointed the source of the issue, but have not pushed my research further (I'm an employee and time is money of course). I will however try to debug further on my personal time.

So here's the cause : the relatableColors function is called twice. The first time (where my first tests ended because I was dumping the $request->route('resourceId')assuming it should never change because we are in a zone edit view), it returns the actual resource ID (zone ID) we're editing. The second time, the resource ID is empty, so this is why the problem I encountered is happening.

Nov
13
3 weeks ago
Activity icon

Started a new Conversation Dynamic Value Doesn't Seem Like A Valid Parameter For A Relatable Query

Hello ! Here I come again with a strange behavior. I'm trying to use the relatable query Nova feature to restrict the colors (from my Color model) shown in my BelongsTo dropdown, but I struck a huge... bug ?

First of all, here's a code snippet pulled from Nova's documentation of what I'm trying to accomplish :

public static function relatableTags(NovaRequest $request, $query)
{
    $resource = $request->route('resource'); // Returns the resource type.
    $resourceId = $request->route('resourceId'); // Returns the resource id.

    return $query->where('type', $resource);
}

Here's my relatable query :

public static function relatableColors(NovaRequest $request, $query)
{
    $resourceId = $request->route('resourceId');

    return $query->whereHas('zones', function($query) use ($resourceId) {
        $query->where('zone_id', $resourceId);
    });
}

So here's the issue : I'm supposed to receive all colors with a zones relation having the current zone ID (contained in $request->route('resourceId')), but no color option is found inside the select.

In my debug case, $resourceId contained a string of "2" (inside the subquery). I told myself that maybe I would get something by casting it to an int... nothing. I then replaced it with an hardcoded 2 (int). Success ! Wait what ? I just casted a string of "2" to an int and it didn't work beforehand. Why ?

I pushed my debug case further. I started by hardcoding a string of "2" instead of an integer, inside a variable placed outside of my subquery. It also worked. Same thing when I casted my hardcoded "2" string to float. Weird...

I then pushed it to an other level (an ugly level if you ask me). I created an anonymous function variable which returned the int casted value of $request->route('resourceId'). No success. I then changed the anonymous function to increment a variable with the help of a loop while the variable was smaller than $request->route('resourceId') (it's big brain time !!!). No success again...

I also tried integer multiplications, additions and substractions on my $request->route('resourceId') variable. No luck...

Can someone give me explanations ? I'm kinda out of ideas.

Activity icon

Started a new Conversation Using Intermediate Table Model Causes Additionnal Pivot Fields To Be Ignored

Hi everyone ! I've started using Nova for one of our new projects and encountered a problem with many to many relations having an intermediate table model.

I want to set an observer on the intermediate table model (ColorZone) to apply some extra operations during Eloquent events (creating, created, updated, etc.).

To be able to use the ColorZone observer, I have to define the intermediate table model via the using method in both colors and zones.

So this is where the issue comes up. Before adding the using method, pivot entries via Nova of either colors or zones were working as expected (create, update, delete, etc.), including the additional is_default pivot field. When adding the using method, pivot entries still work as expected except for the additional pivot field (is_default). The is_default field still shows, but it's not possible to change it. Even if I check the checkbox, it doesn't set is_default to 1.

The same problem occurs in the observer : I can update the ColorZone model, but can't manipulate the is_default field. For example, I tried (for debug purposes), to alter the created_at value inside the observer and it worked. But I can't alter the is_default field.

Now the fun part : if I test what I'm trying to achieve via Tinker, it works. I can set is_default on creation and update.

Here's the problematic relation :

// app\Zone.php

/**
 * The colors that belong to this zone.
 */
public function colors()
{
    return $this->belongsToMany('App\Color')->using('App\ColorZone')->withPivot('is_default');
}


// app\Color.php

/**
 * The zones that belong to this color.
 */
public function zones()
{
    return $this->belongsToMany('App\Zone')->using('App\ColorZone')->withPivot('is_default');
}

And here's the concerned Nova resource field declarations

// app\Nova\Zone.php

BelongsToMany::make('Available colors for this zone', 'colors', 'App\Nova\Color')
    ->singularLabel('Color')
    ->fields(function () {
        return [
            Boolean::make('Default color', 'is_default')
                ->displayUsing(function($field) {return $field;}),
        ];
    }),


// app\Nova\Color.php

BelongsToMany::make('Zones associated to this color', 'zones', 'App\Nova\Zone')
    ->singularLabel('Zone')
    ->fields(function () {
        return [
            Boolean::make('Default color', 'is_default')
                 ->displayUsing(function($field) {return $field;}),
        ];
    }),

So, did I somehow find a Nova bug, or did I do something wrong in my setup ?

Activity icon

Awarded Best Reply on Why Ajax Calls Do Not Execute On Appended Html?

You have to use delegated events

$(document).on('submit', '.deletecomment', function(e) {
    // Your code
});

document here is pretty global, but you could use your .deletecomment parent container instead if you want your event to be localized.

P.S. The more localized your parent selector is, the more efficient your code will be.

Activity icon

Replied to Function Scope After Laravel Mix .js()

Can you post the full error message please and, perhaps, your JS file content ?

Activity icon

Replied to Undefined Class Constant 'users'

And are you sure that the error is not inside the User model ?

Activity icon

Replied to Undefined Class Constant 'users'

Have you declared the Auth Facade ?

use Illuminate\Support\Facades\Auth;
Nov
12
3 weeks ago
Activity icon

Replied to Flip() Collection Between Model And Relations?

It's not a perfect comment/user "flip", but would that work ? (Code not tested. I haven't set up any Laravel project on this computer)

$users = collect();

$yourOriginalCollection->each(function ($comment, $key) {
    $user = $comment->user;
    $user->put('comment', $comment);
    $users->push($user);
});

It's not a perfect "flip" because comment wouldn't be treated as a "legit" relation (not under the relations key managed by the framework)

But I gotta agree with @jaytee

What you want does seem overly complicated.

Activity icon

Replied to Trying To Get Property 'id' Of Non-object For One User Type

Have you tried to put a dd inside your if($this->filled_id == NULL) condition ? As of now, if this condition is hit in your loop somehow, a string is returned and you'd be trying do get the property id of a string (which is not an object), and it will throw the error you're getting.

Activity icon

Replied to Why Ajax Calls Do Not Execute On Appended Html?

You have to use delegated events

$(document).on('submit', '.deletecomment', function(e) {
    // Your code
});

document here is pretty global, but you could use your .deletecomment parent container instead if you want your event to be localized.

P.S. The more localized your parent selector is, the more efficient your code will be.

Activity icon

Replied to Trying To Get Property 'id' Of Non-object For One User Type

You say that you output $post->selecteduser() and got a user in both cases (admin and parent), but was it a single output, or did you output $post->selecteduser() for the entire loop ?

Nov
11
4 weeks ago
Activity icon

Replied to Custom Text For Confirmation Undefined Method ConfirmText()

Did you try to output the content of new Actions\MakeSalesReceiptFromTransaction ?

Activity icon

Replied to Custom Text For Confirmation Undefined Method ConfirmText()

Can you post your MakeSalesReceiptFromTransaction.php file content ?

Activity icon

Replied to How To Unistall Package Which I've Already Installed ?

I do not like put efforts

Well you put more effort in by starting a Laracast discussion than by doing a simple Google search...

Activity icon

Replied to Custom Text For Confirmation Undefined Method ConfirmText()

A resource uses the App\Nova namespace, while actions use the App\Nova\Actions namespace. You have to specify it when creating a new instance of your action.

new Actions\MakeSalesReceiptFromTransaction

Alternatively, you can keep your code as is and use the following at the top of your resource file :

use App\Nova\Actions\MakeSalesReceiptFromTransaction;

But I wouldn't recommend the second option because it can get messy if you use multiple actions in your resource.

Activity icon

Replied to It Could Be More Simple To Change The Nova Logo Image

@travis.elkins I would interpret the info the same way as you are.

Nov
09
1 month ago
Activity icon

Awarded Best Reply on Upgrading From 5.7: UnsignedbigInteger And Migrations

$table->unsignedBigInteger('user_id')->change();

As for your second question, I never performed that specific change, but I think that you shouldn't lose any data. Backup your database for safety, and try it.

Side question : why do you want to upgrade to unsignedBigInteger ? You're expecting over 4 billion users ?

Activity icon

Replied to Upgrading From 5.7: UnsignedbigInteger And Migrations

$table->unsignedBigInteger('user_id')->change();

As for your second question, I never performed that specific change, but I think that you shouldn't lose any data. Backup your database for safety, and try it.

Side question : why do you want to upgrade to unsignedBigInteger ? You're expecting over 4 billion users ?

Activity icon

Awarded Best Reply on Laravel - FontAwesome Not Working, No Errors

Oh I think I know what your issue is. Since you're using the fontawesome.css file, you need to include your light.css, regular.css, solid.css and brands.css.

fontawesome.css doesn't declare any font-face, so that's why it isn't working. If you don't want to be granular, you can use Font Awesome's all.css which declares all font faces within its own CSS file.

<link rel="stylesheet" type="text/css" href="{{ asset('css/fontawesome.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/solid.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/light.css') }}">

<!-- etc. -->
Activity icon

Replied to Laravel - FontAwesome Not Working, No Errors

Oh I think I know what your issue is. Since you're using the fontawesome.css file, you need to include your light.css, regular.css, solid.css and brands.css.

fontawesome.css doesn't declare any font-face, so that's why it isn't working. If you don't want to be granular, you can use Font Awesome's all.css which declares all font faces within its own CSS file.

<link rel="stylesheet" type="text/css" href="{{ asset('css/fontawesome.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/solid.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/light.css') }}">

<!-- etc. -->
Activity icon

Replied to Laravel - FontAwesome Not Working, No Errors

What are your paths in your fontawesome.css file ?

Activity icon

Replied to Laravel - FontAwesome Not Working, No Errors

@laraj You have far, fas, fad, fab and fal with FA Pro

Activity icon

Replied to Laravel - FontAwesome Not Working, No Errors

Can you post an example of how you're using it in your HTML please :) ?

And your public folder structure

Activity icon

Replied to Laravel - FontAwesome Not Working, No Errors

Are Font Awesome class styles being applied or not at all (if you inspect an icon) ?

Activity icon

Replied to How Tpo Get Convert Number To Word

Like @talinon said, you can use NumberFormatter class such as :

$number = 235000;
$numberFormatter = new \NumberFormatter("en_US", \NumberFormatter::SPELLOUT);
$numberInWords = ucfirst($numberFormatter->format($number));

You'll however need to install and/or activate php_intl (setup can vary based on your environment).

If you want to use it in blade, you could pass the NumberFormatter object to your view via your controller, or do something like this (simple code example) :

@php
    $numberFormatter = new \NumberFormatter("en_US", \NumberFormatter::SPELLOUT);
@endphp

@foreach ($numbers as $number)
    {{  ucfirst($numberFormatter->format($number)) }}
@endforeach
Nov
07
1 month ago
Activity icon

Replied to Get Attribute On Models Not To Global Data

No problem ! If you mean that you don't understand, it's simple, it gets the original value as it is stored in the database (bypassing the defined attribute getTanggalLahirAttribute).

Activity icon

Awarded Best Reply on Get Attribute On Models Not To Global Data

Use the following in your form input value

$pns->users->getOriginal('tanggal_lahir')
Activity icon

Replied to Get Attribute On Models Not To Global Data

Use the following in your form input value

$pns->users->getOriginal('tanggal_lahir')
Nov
05
1 month ago
Activity icon

Replied to Change Classes According To Width And Url

For the love of god please post your solution for users with the same issue instead of replying "Got it." and mark it as the best answer...

Activity icon

Replied to When One Checkbox Is Checked Showing Its Related Checkboxes Using Jquery

I see. There is a lot of work to do and it's kinda hard to do it blindfolded (without testing). But I'll try and give you a heads up later today (gotta go back to bed if I don't want to fall asleep while working).

Btw, just realized that the following

$brand=brands::where("segment_id",$segment) ->pluck('brands.brand_name,brands.brand_id')->all();

Should be (in correct Laravel standards)

$brands = Brand::where('segment_id', $segment)->select('brand_name', 'brand_id')->get();
Activity icon

Replied to When One Checkbox Is Checked Showing Its Related Checkboxes Using Jquery

I see multiple things wrong with your JS :

  1. $(document).ready nested inside a function (it can work but it's bad design in my opinion). That being said, I would take it out of the function, put it above it and set the onchange event handler there.
$(document).ready(function() {
    $('.test').on('change', function() {
        getBrands(this.value);
    });
});

function getBrands(segment) {
    ...
}
  1. In your onchange event you call getBrands while getBrand is defined as a function.

  2. This will not work because $sg will always all the same value in that context:

$.each($("input[name='sg[{{$sg->segment_id}}]']:checked"), function(){ favorite.push($(this).val());

That being said, your post is lacking a lot of explanations. I can't seem to understand what related checkboxes you're talking about...

Activity icon

Replied to Validation Only If A Specific Variable Exists

This should work :

$rules = [
    ...
    'trainers' => 'required_without:defaultTrainer.id',
    ...
]

If it doesn't, this will :

$rules = [
    ...
    'trainers' => $request->defaultTrainer['id'] === null ? 'required' : 'nullable',
    ...
]
Nov
04
1 month ago
Activity icon

Replied to Object Arrays, Grouping By Value And Separating Into Multiple Arrays.

You only need a single easy loop. Lodash is not needed.

Let's say the array you posted above is $students

// Array containing grouped results
$studentsByHairColor = [];

// Loop through each object in your array and assign the student name to a key representing his or her hair color
foreach ($students as $student)
    $studentsByHairColor[$student->Hair][] = $student->Name;

// Optional : Sort array's first level keys (hair colors) in alphabetical order
ksort($studentsByHairColor);

As simple as that !