piljac1

piljac1

Member Since 3 Weeks Ago

Experience Points
3,540
Total
Experience

1,460 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
6
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 1
3,540 XP
Oct
18
2 days ago
Activity icon

Replied to Url Confirmation

Use double quotes for string interpolation

@component('mail::button', ['url' => "http://serviceac.test/requests/payment/{$permintaan->id}"])
Activity icon

Replied to "numeric Value Expected"

No problem :) ! Can you try the second solution I proposed ? (Just curious to see if that was the issue with string type lat/long haha)

Activity icon

Replied to Numbering Other Than Increment

Why is it important to get the numbers (IDs) "right" when outputting different types of user ? In which context will it be used ? Couldn't you simply use your collection's keys (+ 1) to achieve what you're trying to obtain such as :

foreach (User::where('role', 'admin')->get() as $key => $admin) {
    // Do stuff
}

Edit: if you need a solution in Blade, see @siangboon answer

Activity icon

Replied to "numeric Value Expected"

Also, have you tried like this ?

 ->whereGeoDistance('location_latlon', "{$request->longitude},{$request->latitude}", '100km')

According to the Geo-distance query doc, only numbers are passed in an array. Lat/long of string type are passed as a single string, like the following :

"40,-70"
Oct
17
3 days ago
Activity icon

Replied to "numeric Value Expected"

Have you tried casting ?

 ->whereGeoDistance('location_latlon', [floatval($request->longitude), floatval($request->latitude)], '100km')
Oct
10
1 week ago
Activity icon

Replied to Custom Validation

@movepixels Alright !

Activity icon

Replied to Custom Validation

It's a bit hard to help you without any code sample to start from, but I would do something along those lines (get rid of your current after_or_equal validator) :

// In your validation
$request->validate([
...

    'start_date' => [
        'required', // Whatever your other validations are
        'date',
        function ($attribute, $value, $fail) {
            try {
                $date = Carbon::parse($value);

                // If the date is not equal to the model's start date
                // ($model here would be the model being updated)
                if ($date->ne($model->start_date)) {

                    // If the date is before the current date, make the validation fail
                    if ($date->lt(now())) {
                        $fail($attribute . ' must be a date after or equal to today.');
                    }
                }
            } catch (\Exception $err) {
                $fail($attribute . ' is not a valid date.');
            }
        },  
    ],

...
]);

Use a similar logic for the end_date.

If you want to avoid using a try catch, you can use the bail validator to make the validation stop if the date validation fails.

// In your validation
$request->validate([
...

    'start_date' => [
        'bail',
        'required', // Whatever your other validations are
        'date',
        function ($attribute, $value, $fail) {
            $date = Carbon::parse($value);

            // If the date is not equal to the model's start date
            // ($model here would be the model being updated)
            if ($date->ne($model->start_date)) {

                // If the date is before current date, make the validation fail
                if ($date->lt(now())) {
                    $fail($attribute . ' must be a date after or equal to today.');
                }
            }
        },  
    ],

...
]);

Let me know if it works !

Oct
09
1 week ago
Activity icon

Replied to Policy Never Called

Why is that line commented out ?

'App\Model' => 'App\Policies\ModelPolicy'
Activity icon

Replied to Difference Between $request->input('name') And $request->name ?

When using $request->attribute, Laravel will first look for the parameter's value in the request payload. If it is not present, Laravel will search for the field in the route parameters*.

$request->input('attribute') is pretty much the same, but it will also accept array inputs with the dot syntax: $request->input('attribute.0.name') or $request->input('attribute.*.name'). You can set a default value as well with: $request->input('attribute', 'defaultValue')

*From Laravel's docs

Oct
06
2 weeks ago
Activity icon

Replied to Simple SQL Query Vs Eloquent

@jlrdw That's what I said in the next sentence :P I edited my post to avoid confusion.

Activity icon

Replied to Simple SQL Query Vs Eloquent

Eloquent is technically slower, because it has to build the actual SQL query, but I wouldn't say that the difference is noticeable (except if Eloquent is not used correctly in the context). For example, the following code example will run two separate SQL queries :

Book::with('author')->where('title', 'like', '%a%')->get();

The following one only runs one query and is multiple times faster than the one above :

DB::table('books')->join('authors', 'books.author_id', 'authors.id')->where('title', 'like', '%a%')->get();

An entirely raw query equivalent to the one above is performed practically (I can almost say equally) as fast as the one above :

DB::select("select * from books join authors on books.author_id = authors.id where title like '%a%'");

As for safety, Eloquent is safer than a raw SQL query because it uses PDO out of the box (which prevents SQL injection with parametered queries). You can still use bindings with raw SQL queries though.

Activity icon

Replied to Last Inserted Record UUID Returns 0

The Laravel functionality of being able to retrieve the ID of a created element only works if the ID is set as autoincrement.

In your case, you'll need to generate a new UUID (returning the generated value in a variable) and then use this variable moving on.

Or you can try the solution depicted here : https://stackoverflow.com/questions/17280616/laravel-lastinsertid-with-uuid-pk

Activity icon

Replied to Laravel Ajax Returns Self HTML

Oh. I just saw you updated your post and it really is returning your current page's HTML. At the same time, I just realized what your error is. In your AJAX params you wrote URL instead of url. JavaScript is case sensitive so your URL property is not considered the same as url.

Activity icon

Replied to Laravel Ajax Returns Self HTML

You AJAX call is sent after your view is already loaded and when you click the delete button, so don't expect your current view to "die". You'll be able to see your die (if you output something of course) in your browser's network tab.

As for the returned HTML code you mentioned, are you sure it is the exact same HTML code ? Because it sounds like it might be a Laravel error view.

Activity icon

Replied to Mass Asignment

An array in an ID field ? Can you elaborate on your database structure ?

Oct
05
2 weeks ago
Activity icon

Replied to Strange Eloquent Behavior: Trying To Get Property 'name' Of Non-object And Object Exist

What @ftiersch said. If you want to avoid this issue, you can use optional such as :

return optional($feature)->name;

That way it won't crash but will return null if no Feature model matching the $metaId is found.

Activity icon

Replied to Migrations - Adding Columns With FALSE As Default Value

You wrote

deafult(false);

Instead of

default(false);
Activity icon

Replied to Laravel Echo Problem, Cannot Read Events

Did you run your queue ?

php artisan queue:work

// or queue:listen if you want to continuously process jobs on the queue

php artisan queue:listen

Broadcasting uses the default queue (except if you stated otherwise in your broadcasting settings) and doesn't work if the queue is not listening.

Oct
04
2 weeks ago
Activity icon

Replied to Add Task To Mix To Call API

I do not know much about Mix since I started using it a couple of weeks ago, but I would personally try the following:

  1. Create a custom console command (php artisan) that would upload compiled files to the desired server
  2. Add it to your npm run dev / npm run watch commands in your package.json file (perhaps your command would have a param to indicate the destination site - dev or prod)
"scripts": {
    // "uploadToServer" would be the command name you choose of course

    "dev": "npm run development && php artisan uploadToServer dev",

    // other npm commands

    "prod": "npm run production && php artisan uploadToServer prod",

    // other npm commands
},
  1. Call "npm run dev" or "npm run prod" as usual, but now it will execute the command you created afterwards

Is it the best way to accomplish what you're trying to do ? I couldn't answer due to my limited Mix knowledge. Would it work ? There are pretty good chances that it would.

Activity icon

Replied to Real-time Issue: Broadcast(new OneChatEvent()) Will Not Be Triggered To View

Simple question: are you running your broadcast queue (default queue is the default setting) ?

Activity icon

Replied to Why Will My Controller Not Accept The Data From My Ajax Call?

Have you checked your network tab in your browser to get more info ? It sounds like it could be an error 500.

Activity icon

Replied to Delete Item On Foreach Loop

@atfinho No problem ! Please mark it as best answer if it was the solution you were looking for so others searching for the same issue can see it on top :) Thank you and have a good day of programming !

Activity icon

Replied to Delete Item On Foreach Loop

You can use onDelete('SET NULL') on your foreign key declaration, such as :

$table->foreign('zipcode_id')->references('id')->on('zipcodes')->onDelete('SET NULL');

Don't forget to to set your foreign key id ("zipcode_id") as nullable

$table->integer('zipcode_id')->unsigned()->nullable();
Sep
26
3 weeks ago
Activity icon

Replied to Re-use A Component In VueJS

If you're trying to have a different style for each individual component, you can add a style tag inside your Vue component with the "scoped" attribute.

Example:

<style scoped>
    .round-sorting {
       color: red;
    }
</style>

View this link for more detail : https://vue-loader.vuejs.org/guide/scoped-css.html#mixing-local-and-global-styles

Activity icon

Started a new Conversation Best Way To Add A Dynamic Attribute To Default Validation Messages ?

Hi guys ! I'm questionning myself to know what is the best way to implement an extra dynamic attribute in a default validation message (validation.php).

I know it is possible to redefine specific attribute rules (which overide the generic rules) with the following:

// validation.php

'custom' => [
    'refund_amount.*' => [
        'min' => "The :attribute must be at least :min.",
    ],
],

But at the same time, it only implies that you can change the sentence, but not the actual dynamic attributes themselves.

I would like to add a dynamic ":field" attribute in the above code snippet:

// validation.php

...
        'min' => "The :field :attribute must be at least :min.",
...

I was wondering if there was a "standardized" way to do so, because I found a workaround (in the FormRequest itself), by looping through my refund_amount inputs (array of inputs with a key containing their IDs) and set each specific validation messages for the array (ex.: refund_amount.1.min, refund_amount.2.min, etc.). To do so, I'm calling a slightly modified version of the above translation and assign the :field attribute value. But it doesn't seem that natural of a solution:

// app/Http/Requests/ProcessRefund.php

/**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages()
    {
        $messages = [];

        if (!is_null($this->input('refund_amount'))) {
            foreach ($this->input('refund_amount') as $id => $refundAmount) {
                $field = Field::find($id);

                if (!is_null($field))
                    $messages["refund_amount.{$id}.min"] = __('validation.custom.refund_amount.min', ['field' => $field->value]);
            }
        }

        return $messages;
    }
        

Here's the slightly modified translation hierarchy (no more .* after refund_amount, because it was considered as an other array level by the __() translation function):

// validation.php

'custom' => [
    'refund_amount' => [
        'min' => "The :field :attribute must be at least :min.",
    ],
],

Can anyone point me to a more "native" way to accomplish what I'm doing, or there's no other way at the moment ?

Thanks in advance,

  • Jacob