nabilunfarhanun

nabilunfarhanun

Software Engineer at Colgis BD

Member Since 11 Months Ago

Pabna

Experience Points
14,110
Total
Experience

890 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
136
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.

Level 3
14,110 XP
Aug
20
2 months ago
Activity icon

Started a new Conversation How To Run Query With Model Function?

So, I have a model for products of a website. In the model I use a function to calculate the price of the product. It is something like this,

class Product extends Model
{

    public function price()
    {
        // logic to calculate price
        // this logic may depend on many things and may change in future.
        return $price
    }
}

I can view this successfully in my blade view by using following.

{{ $product->price() }}

However, I want to use it to do some query. There may be other filtering. Those are working fine. But whenever I want to use the return value of price function in the query it is giving an error.

$products = Product::query();
//There may be some other filtering query
$products = $products->where('price()','<',request('maxPrice'));
//Maybe some more filtering query
$products = $products->get();
return view('product',compact('products'));

My question is how can I run query with the price function of my model. Also, if you can think of an alternative way to achieve this then please teach me.

Aug
09
2 months ago
Activity icon

Started a new Conversation How To Dry Up This Part Of My Code?

I am submitting two forms from same page with ajax. One is to create and another is to update. As they look very similar, my gut says their should be a way to dry up this form. But I am not quite getting it. can you please give me tips on how I can dry this up?

This is the first form,

<script type="text/javascript">
        $("#createForm").submit(function(e) {
            e.preventDefault();
            var form = $(this);
            var url = form.attr('action');
            $.ajax({
                    type: "POST",
                    url: url,
                    data: $('#createForm').serialize(),
                    success: function(data)
                    {
                        if(data=="success")
                        {
                            location.reload();
                        }
                        else
                        {
                            var html = "<ul>";
                            for(var dat in data)
                            {
                                for (var x in data[dat])
                                {
                                    html = html+"<li>"+data[dat][x]+"</li>";
                                }
                            }
                            html = html+"</ul>";
                            $("#createErrors").attr("class","alert alert-danger");
                            $("#createErrors").html(html);
                        }
                    }
                });
        });
    </script>

This is the second form,

<script type="text/javascript">
        $("#updateForm").submit(function(e) {
            e.preventDefault();
            var form = $(this);
            var url = form.attr('action');
            $.ajax({
                    type: "POST",
                    url: url,
                    data: $('#updateForm').serialize(),
                    success: function(data)
                    {
                        if(data=="success")
                        {
                            location.reload();
                        }
                        else
                        {
                            var html = "<ul>";
                            for(var dat in data)
                            {
                                for (var x in data[dat])
                                {
                                    html = html+"<li>"+data[dat][x]+"</li>";
                                }
                            }
                            html = html+"</ul>";
                            $("#updateErrors").attr("class","alert alert-danger");
                            $("#updateErrors").html(html);
                        }
                    }
                });
        });
    </script>
Jul
09
3 months ago
Activity icon

Started a new Conversation Law Of Demeter.

I am new to programming and got introduced to the law of demeter. I am having trouble understanding it.

For example, I have developed a ecommerce related page. In that page, a list of product will be showed with its supplier address. Naturally only supplier's id is in the product page.

So, my solution was to show it like this, {{$product->supplier->address()}}

The product and supplier relation was defined well. So the output was working without any problem.

However, one of the fellow developers suggested I should use something like, {{$product->supplierAddress()}}. And from inside the supplier function I should ask the supplier in question to return it's address.

I understand the idea behind the law of demeter is to create loose coupling. But I feel like still the product object and supplier object are still related to each other.

My question is two fold. Is the other solution better and follow the law of demeter? If yes, then can you provide a scenario where my code will be problematic and not adaptable to change?

Thanks in advance

May
14
5 months ago
Activity icon

Started a new Conversation Best Practice For Validation And Dry Principle

What I read from the internet is it is good practice to validate both in front end and back end. Front end validation is needed for user friendliness. And back end validation is needed for security.

However how can I follow the dry principle while doing validation in both end?

For example, suppose, I have a form where it will accept password. And the password minimum length is 6. I did the back end validation with form controller and the front end validation with javascript.

However, if somehow the minimum length is changed to 8 then I need to change the length in two places. One is in back end; another in front end. Isn't it violating the dry principle? How can I manage this in such a way that I would need to change in only one place? What is the best practice in this case?