mrkarma4ya

mrkarma4ya

Member Since 1 Year Ago

Experience Points
10,380
Total
Experience

4,620 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
71
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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
10,380 XP
Jun
27
3 months ago
Activity icon

Started a new Conversation Generate Factory With Custom Data

Until now, I have been generating factories using faker, which is great.

But for categories, I want to create 6 of them with custom names, not generated ones.

Instead of

$factory->define(Category::class, function (Faker $faker) {
    return [
        'name' => $faker->unique()->word()
    ];
});

I want to do something like this:

$factory->define(Category::class, function (Faker $faker) {
    return [
        'name' => ['a','b','c','d','e','f']
    ];
});

The above code doesn't work, so how do I achieve this? I don't want to manually put them into database, because they need to be 'seedable' since I'll be running migrate:fresh a lot for testing.

Jun
26
3 months ago
Activity icon

Replied to Getting Min/Max Price In A Product List Api

@frankielee I know the pagination part, just wanted to add more info.

Actually, I found the solution: https://laravel.com/docs/7.x/eloquent-resources#adding-meta-data

Now I have this:

"meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 100,
        "path": "http://learnapi.test/api/products",
        "per_page": 1,
        "to": 1,
        "total": 100,
        "max_price": 99770,
        "min_price": 1898
    }

Is this the RESTful way to do it?

Activity icon

Started a new Conversation Getting Min/Max Price In A Product List Api

I want to make an API endpoint which gets all products with paginate 12 as well as the max and min price of the products. Desired output is something like:

{
    "data": [
        {
            "id": 1,
            "category_id": 1,
            "name": "et",
            "description": "Est aut temporibus cum voluptatem et eos. Sint repudiandae est quo quia nihil aliquid. Quae ipsam cupiditate explicabo adipisci.",
            "price": "2.08",
            "category": {
                "id": 1,
                "name": "id",
                "product_count": null,
                "url": "https://learnapi.test"
            }
        // 11 more products
        }
    ],
    "links": {
        "first": "http://learnapi.test/api/products?page=1",
        "last": "http://learnapi.test/api/products?page=100",
        "prev": null,
        "next": "http://learnapi.test/api/products?page=2"
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 100,
        "path": "http://learnapi.test/api/products",
        "per_page": 1,
        "to": 1,
        "total": 100,
    }
    "max_price": 1000,
    "min_price": 20
}

How can I do this?

Jun
20
4 months ago
Activity icon

Started a new Conversation Laravel + Vue, Filter With Vue Only Or Filter With Api Calls?

Hi,

I'm learning Laravel API + Vue right now, and I have a list of products and categories. Now I wan't to create a filter with Categories, but I'm running into a dilemma. Should I filter with Vue Only or Filter with Api Calls?

Filter with Vue:

Get all products with API then filter them through vue. It works, but if I have many products then the API call will take too long and I guess high memory usage as well. I could paginate the API, but then the filter would work on the paginated products only, not all products in DB.

Filter with API:

I found this tutorial: https://www.youtube.com/watch?v=ZZkROqT83t8&t=338s

Firstly, I'm finding it a bit difficult to understand how or why it's working. Second, I cloned the repo to test it out, and if I keep using the filter frequently, it runs into 429 Too Many Requests error, so I don't know if this is the proper way. Here: https://youtu.be/_6j7Lgd1ZyM

So, which option would be better, and is there a more in-depth tutorial on this topic?

Jun
15
4 months ago
Activity icon

Replied to Looking For A Tutorial On API For Recent Laravel Versions

Thanks for the confirmation!

Activity icon

Started a new Conversation Looking For A Tutorial On API For Recent Laravel Versions

I'm looking for a good tutorial on API for recent Laravel versions, preferably in video form.

Most results I've found are for older versions or the ones that use additional packages like Passport, which I'm not sure I should be diving into with 0 knowledge of APIs.

I found a video for Laravel 5.5 (https://www.youtube.com/watch?v=4pc6cgisbKE), is it relevant for Laravel 7?

Apr
21
5 months ago
Activity icon

Replied to How Can I Have To Get Routs That Go To The Same Page

Both URLs are the same, i.e. /shop/{variable}

You need different URLs, something like

/shop/products/{product}
/shop/category/{category}
Activity icon

Replied to Silber/bouncer Package To Assign Roles

Its mentioned in the github page readme.md - https://github.com/JosephSilber/bouncer

Adding roles and abilities to users is made extremely easy. You do not have to create a role or an ability in advance. Simply pass the name of the role/ability, and Bouncer will create it if it doesn't exist.

Note: the examples below all use the Bouncer facade. If you don't use facades, you can instead inject an instance of Silber\Bouncer\Bouncer into your class.

Creating roles and abilities

Let's create a role called admin and give it the ability to ban-users from our site:

Bouncer::allow('admin')->to('ban-users'); That's it. Behind the scenes, Bouncer will create both a Role model and an Ability model for you.

If you want to add additional attributes to the role/ability, such as a human-readable title, you can manually create them using the role and ability methods on the Bouncer class:

    $admin = Bouncer::role()->firstOrCreate([
    'name' => 'admin',
    'title' => 'Administrator',
]);

$ban = Bouncer::ability()->firstOrCreate([
    'name' => 'ban-users',
    'title' => 'Ban users',
]);

Bouncer::allow($admin)->to($ban);
Apr
20
6 months ago
Activity icon

Replied to JQuery Not Working In App.js

I think I found the issue, back when I created the project I added the auth scaffolding with --vue parameter (I think), so the vue instantiation code was interfering would be my guess.

It worked after I commented out the code:

const app = new Vue({
     el: '#app',
 });

Another solution I found was wrapping my jquery code in a $(document).ready() block, so the code looks like this:

Activity icon

Started a new Conversation JQuery Not Working In App.js

I have a small script for search input in jQuery, if I put it in my main.js file and compile it down to app.js, it won't work.

But if I put it inline in my layouts file, just after loading app.js, it works. The order of compilation is correct too, jquery is included before the main.js.

This Works :-

<!-- Layouts File -->
<script src="{{asset('js/app.js')}}"></script>
  <script type="text/javascript">
    $('#search').on('keyup',function(){
        alert('Triggered);
     })
</script>

But this doesn't: -

//main.js
$('#search').on('keyup',function(){
        alert('Triggered);
     })
//app.js
require('./jquery.min.js');
require('./popper.min.js');
require('./bootstrap');
require('./main.js');

If I open app.js in browser, I can see that the script in main.js is loaded, but it won't work. I can't figure out why.