piljac1

piljac1

Member Since 4 Months Ago

Experience Points
15,350
Total
Experience

4,650 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
23
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 4
15,350 XP
Feb
17
2 days ago
Activity icon

Replied to How Would You Structure A Winning Bid Relationship?

@larsonator Careful, an auction with a winning bid doesn't mean it's over. It can be seen as the current winning bid as long as the auction hasn't expired.

Activity icon

Replied to How Would You Structure A Winning Bid Relationship?

There are multiple solutions, but I would add a winning_bid_id foreign key to the auctions table as you proposed. Your current code will probably be fine for a while, but as the database entries multiply, it will get slower and slower. As for the how can I update the column ? question, simply update it each time a new bid is submitted (that takes into account that you have a solid validation process to avoid data inconsistency).

Feb
13
6 days ago
Activity icon

Awarded Best Reply on Determine What Model A Value Came From.

There are multiple solutions to this, but if you want to keep everything server side, you could use a {modelClassName}.{id} notation as option values and explode it server side.

Example:

<select name="eventdateable" class="form-control" id="eventdateable_id">
    <option></option>
    @foreach($mergedFamily as $mf)
        <option value="{{ addslashes(get_class($mf)) . '.' . $mf->id }}">{{ $mf->name }}</option>
    @endforeach
</select>

P.S. I know HTML4 is old, but if you want to support it, this won't work because backslashes are not authorized in the older spec. You would need to replace addslashes by class_basename to only get the model class name without the namespace. Then you would append the namespace on the server side when processing your form data.

After doing that, you could explode the value contained within your eventdateable request value and collect the desired info:

// Of course you could (should) add validation to avoid errors if the request value is null or not well formatted
$eventdateablePair = explode('.', $request->eventdateable);

// Your eventdateable_type
$eventdateableType = $eventdateablePair[0];

// Your eventdateable_id
$eventdateableId = $eventdateablePair[1];

When assigning the eventdateable_type to your model (and then your database), you might have an escaping issue. If that's the case, add another addslashes to your existing front-end logic, or add it in the back-end if you want.

Feb
12
1 week ago
Activity icon

Replied to Determine What Model A Value Came From.

@sinnbeck is right you know ;) Thanks in advance (and thanks @sinnbeck)

Feb
11
1 week ago
Activity icon

Replied to Determine What Model A Value Came From.

There are multiple solutions to this, but if you want to keep everything server side, you could use a {modelClassName}.{id} notation as option values and explode it server side.

Example:

<select name="eventdateable" class="form-control" id="eventdateable_id">
    <option></option>
    @foreach($mergedFamily as $mf)
        <option value="{{ addslashes(get_class($mf)) . '.' . $mf->id }}">{{ $mf->name }}</option>
    @endforeach
</select>

P.S. I know HTML4 is old, but if you want to support it, this won't work because backslashes are not authorized in the older spec. You would need to replace addslashes by class_basename to only get the model class name without the namespace. Then you would append the namespace on the server side when processing your form data.

After doing that, you could explode the value contained within your eventdateable request value and collect the desired info:

// Of course you could (should) add validation to avoid errors if the request value is null or not well formatted
$eventdateablePair = explode('.', $request->eventdateable);

// Your eventdateable_type
$eventdateableType = $eventdateablePair[0];

// Your eventdateable_id
$eventdateableId = $eventdateablePair[1];

When assigning the eventdateable_type to your model (and then your database), you might have an escaping issue. If that's the case, add another addslashes to your existing front-end logic, or add it in the back-end if you want.

Feb
08
1 week ago
Activity icon

Replied to Change Parent_id To Null In Child Model When Parent Deleted

I agree with @snapey

It makes no sense to me that every foreign key use cases would imply that they should never be null. @snapey gave some excellent examples. I'm waiting for your point of you @bugsysha because I feel like your reasoning might make me understand your side. This is an interesting debate.

Activity icon

Replied to Apply ShouldQueue For Specific Notification Channels

As far as I know, this subject has been discussed, but never implemented (at least since summer 2019 for sure).

The only way to accomplish what you want for now would be to create two separate notifications.

Feb
07
1 week ago
Activity icon

Replied to How To Set Validation On Dynamic Dependent Dropdown

Is it possible to detail what you're trying to accomplish exactly. With the info you gave us, we could interpret it many ways. Are you asking if it is possible to validate a field based on an other on form submit ? Are you asking how is it possible to show an error in "real time" for Segment Name when an Industry Name is selected ? Please elaborate. Thanks !

Activity icon

Replied to How To Round Decemle Number In Php?

@fabriciog I tried your code and it works as expected, but if you want 42% based on 42.857142857143%, you should use the floor function instead.

Jan
16
1 month ago
Activity icon

Awarded Best Reply on Form Not Getting Data From Database

I know that you're using booleans, but booleans are represented with 1 and 0 (TINYINT) in the database. You're sending true as a string parameter, which will not match 1. Try replacing your true get params with 1, or add this logic to all your boolean fields in your query builder:

$request['vegan'] == 'true' ? 1 : 0
Activity icon

Replied to Form Not Getting Data From Database

I know that you're using booleans, but booleans are represented with 1 and 0 (TINYINT) in the database. You're sending true as a string parameter, which will not match 1. Try replacing your true get params with 1, or add this logic to all your boolean fields in your query builder:

$request['vegan'] == 'true' ? 1 : 0
Jan
15
1 month ago
Activity icon

Replied to Form Not Getting Data From Database

Replace your true strings by 1 and it should solve your issue. If it doesn't, take out the ->get() from your Recipes query and after you've done that, use dd($recipes->toSql(), $recipes->getBindings()) to obtain the generated SQL query and bindings passed to it. If the query looks ok, replace ? in the query with your bindings and try to adjust them until you get desired results. Once you've done that, you'll know what part of your code is incorrect.

Activity icon

Replied to Use Web Or Api Route When Building An Api.

Main differences between web and API routes:

  1. API routes are prefixed with /api

  2. API routes are throttled to avoid abusive numbers of requests in a short sequence

  3. API routes are stateless, which means:

Stateless means there is no record of previous interactions and each interaction request has to be handled based entirely on information that comes with it.

Jan
06
1 month ago
Activity icon

Replied to Laravel Pass Data To The Another Page

In your Reservation model, get rid of the "s" in the locations relation :)

Edit : @tisuchi's got a point. Pass the ID to your route and use it to associate.

Also, in your store form, your select is missing a name (type). So your $request->get('type') will return null.

Also, you could just use the $request->type nomenclature to shorten things up.

Dec
25
1 month ago
Activity icon

Awarded Best Reply on How To Handle Dynamic Input Filed With One V-model

So you want to get rid of undefined values and keep [2:"5", 3:"4"]or do you wish to only keep [2:"5"] for example ?

If you want to get rid of the undefined items, use an Object instead of an Array. Arrays start from 0, so if for example your IDs would be 75 and 76 instead of 2 and 3, you would have 75 undefined values before the 75 key.

Changing your qnt to an Object would give you {2: "5", 3: "4"}. If you wish to convert the object to an Array afterwards, you can use Object.entries(form.qnt) and it will output :

[
    0: [0: 2, 1: "5"],
    1: [0: 3, 1: "4"]
]
Activity icon

Replied to How To Handle Dynamic Input Filed With One V-model

So you want to get rid of undefined values and keep [2:"5", 3:"4"]or do you wish to only keep [2:"5"] for example ?

If you want to get rid of the undefined items, use an Object instead of an Array. Arrays start from 0, so if for example your IDs would be 75 and 76 instead of 2 and 3, you would have 75 undefined values before the 75 key.

Changing your qnt to an Object would give you {2: "5", 3: "4"}. If you wish to convert the object to an Array afterwards, you can use Object.entries(form.qnt) and it will output :

[
    0: [0: 2, 1: "5"],
    1: [0: 3, 1: "4"]
]
Activity icon

Replied to Improve Query Binding Using Array For Where In Statement

Not sure what you're trying to accomplish exactly, but you should use query builders instead of raw SQL

Example (based on your code block) :

DB::table('table_name')
    ->whereIn('iid', $data)
    ->whereIn('iv_status', ["N", "Y", "A"])
    ->get();

You can get rid of your $ids variable. No need to use implode with query builders. As for your array_map, I don't understand what you're trying to accomplish with it, so I'll let you update this piece of code to suit your needs.

Dec
21
1 month ago
Activity icon

Replied to Can't Access Data Property From Parent In Slot Child Component

You can access your parent component instance directly

this.$parent.computedResults

Or save your computedResults in a Vuex state property and get it in the child.

Activity icon

Replied to Troubleshooting INTERNAL SERVER ERROR 500

Error 500 is often caused by a code logic error. So don't rule out your code. There must be some kind of pattern your users are following that you don't. Can your users retrace the steps they took to encounter that error ? That would help you out. Also, the error would be more verbose in a local environment. It will tell you what was the stack of operations and what failed.

Dec
20
1 month ago
Activity icon

Awarded Best Reply on Cannot Redeclare RandomPostType() [Custom Function On Model Factory]

Try implementing an existance test on your two declared functions

if (!function_exists('randomPostType')) {
    function randomPostType() {

        $post_type = ['forum','video','image','article'];
        $random_key = array_rand($post_type, 1);
        return $post_type[$random_key];
    }
}

if (!function_exists('randomEmbedCode')) {
    function randomEmbedCode() {

        $embed_code = [
            '<iframe class="embedly-embed-1"></iframe>',
            '<iframe class="embedly-embed-2"></iframe>',
            '<iframe class="embedly-embed-3" ></iframe>'
        ];
        $random_key = array_rand($embed_code, 1);
        return $embed_code[$random_key];
    }
}
Activity icon

Replied to Cannot Redeclare RandomPostType() [Custom Function On Model Factory]

Try implementing an existance test on your two declared functions

if (!function_exists('randomPostType')) {
    function randomPostType() {

        $post_type = ['forum','video','image','article'];
        $random_key = array_rand($post_type, 1);
        return $post_type[$random_key];
    }
}

if (!function_exists('randomEmbedCode')) {
    function randomEmbedCode() {

        $embed_code = [
            '<iframe class="embedly-embed-1"></iframe>',
            '<iframe class="embedly-embed-2"></iframe>',
            '<iframe class="embedly-embed-3" ></iframe>'
        ];
        $random_key = array_rand($embed_code, 1);
        return $embed_code[$random_key];
    }
}
Dec
14
2 months ago
Activity icon

Replied to Mvp Using Nova

@bobbybouwmann It's a time saver for sure and is pretty stable if you're not using in dept features. It can be a good choice for customers with limited budgets, but for bigger budget customers with specific needs, I wouldn't recommend it.

Activity icon

Replied to Mvp Using Nova

While I agree with @bobbybouwmann, I wouldn't use Nova in production. I personally hated the Nova experience because I feel like Nova itself is a MVP. It's extremely rigid, lacks a lot of basic CMS features and still has a lot of bugs. In addition, the two things that irritated me the most was the UX (way too many clicks and doubtful UX decisions in general), as well as the support behind Nova. I've seen multiple highly pertinent requests get shut down in a pretty harsh way with a pathetic reply.

I've not yet used other Laravel CMS options, but I know that some people moved from Nova to October CMS and enjoyed their experience.

Dec
13
2 months ago
Activity icon

Awarded Best Reply on How To Send Ajax Request On Data That Added By Another Ajax Request ?

I'm betting that you're not using delegated events. So your dynamically added elements do not benefit from the same logic than your content already present on page load. If you're using jQuery, you can solve that easily :

$(document).on('click', '.your-target-class', function () {
    // Your logic
});

The $(document) part above should be something more specific for better performances (ex. : $('.container')), because binding the listener to the document will capture all clicks made on the page.

.your-target-class would be the class that you would want to target (ex. : .category)

Activity icon

Replied to How To Send Ajax Request On Data That Added By Another Ajax Request ?

I'm betting that you're not using delegated events. So your dynamically added elements do not benefit from the same logic than your content already present on page load. If you're using jQuery, you can solve that easily :

$(document).on('click', '.your-target-class', function () {
    // Your logic
});

The $(document) part above should be something more specific for better performances (ex. : $('.container')), because binding the listener to the document will capture all clicks made on the page.

.your-target-class would be the class that you would want to target (ex. : .category)

Dec
11
2 months ago
Activity icon

Replied to Table Not Null

Post all your concerned migrations please. So we can get a global idea of what's going on.

Activity icon

Replied to CSS Overlap

Which stylesheets are conflicting exactly ? All of them or specific ones ? What happens and what do you expect ? (Just trying to get as much info as I can)

Activity icon

Replied to Table Not Null

Also you don't need your unsigned() statements

Activity icon

Replied to Table Not Null

Then this is part of your issue. A foreign key must reference a primary key.

Activity icon

Replied to Table Not Null

Do you have a primary key defined in your banks table ? (bigIncrements or some sort of primary key)

Activity icon

Replied to Table Not Null

The error is pretty explicit. You already have an "employees" table. Delete it from your database by doing a migration rollback if it was issued from a migration. Else, delete it manually and re-run your migration.

Activity icon

Replied to CSS Overlap

Have you imported bootstrap stylesheet(s) first and then your theme's stylesheet(s) ?

Activity icon

Replied to Index Issue

We can't help you without some code...

Activity icon

Replied to CSS Overlap

What do you mean by CSS overlap ? Styles overwriting others or container overflow ?

Dec
09
2 months ago
Activity icon

Replied to "value.toString(...).toUppercase Is Not A Function"

You're missing a capital C in your toUpperCase function :)

Dec
08
2 months 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 months 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
2 months 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 months 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 months 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 months 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 months 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
3 months 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 months 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]');