MartinZeltin

MartinZeltin

Member Since 1 Year Ago

Experience Points
27,560
Total
Experience

2,440 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
180
Lessons
Completed
Best Reply Awards
0
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 6
27,560 XP
Aug
04
12 hours ago
Activity icon

Started a new Conversation Giving Users An Update Option From The App

I know that I can deploy a newer version of the app by git pull and then running the artisan migrate commands. But how could I give the user a button that they can click (from the frontend) and the newest version will be deployed automatically?

How is this one? Has anyone done this before?

Thanks!

Aug
03
1 day ago
Activity icon

Replied to Giving Users An Option To Roll Back To Older Versions Of App

@jeffdavis Good points. I am thinking about if the new version turns out buggy and the user wants to revert back to the old version... could it be done easily somehow..?

Activity icon

Replied to Giving Users An Option To Roll Back To Older Versions Of App

Does anyone have any experience with this?

Activity icon

Started a new Conversation Giving Users An Option To Roll Back To Older Versions Of App

I have an app where users can update to the latest version. I was wondering if it is at all possible to give users an option to somehow... revert back to an older version of the app - without losing any data (like blog posts, comments etc.)

Has this been done before and how?

P.S. I am creating the app using Laravel + Vue

Jul
28
1 week ago
Activity icon

Commented on Teleport

How about a real world Vue 3 + Vuex app?

Jul
23
1 week ago
Activity icon

Replied to How To Add Collection Items To Another Item?

I ended up doing something like this...

$parts = $cars_and_parts->where('is_car_part', 1);

$cars_and_parts->each(function($item) use ($parts) {
    $parts_list = $parts->where('car_id', $item->id);

    if (count($parts_list) > 0) {
        $item->car_parts = $parts_list->values();
    }
});
Activity icon

Replied to How To Add Collection Items To Another Item?

I see that there is no update() method for Collections so that didn't work...

Activity icon

Started a new Conversation How To Add Collection Items To Another Item?

I have this Cars_And_Parts collection that contains both cars and car parts. I would like to take all the car parts and add each to the correct car's car_parts array. I can't seem to figure out how to do this using Collection methods.

Here is my original $Cars_And_Parts Collection

[
    {
        "id": 1,
        "description": "Tesla Model X",
        "car_parts": [],
    },

    {
        "id": 2,
        "description": "Nissan Leaf",
        "car_parts": [],
    },
    
    {
        "id": 3,
        "description": "Tesla Engine",
        "is_car_part": true,
        "car_id": 1,
    },
    
    {
        "id": 4,
        "description": "Nissan battery",
        "is_car_part": true,
        "car_id": 2,
    },
    
    {
        "id": 5,
        "description": "Nissan lights",
        "is_car_part": true,
        "car_id": 2,
    },
]

And after adding all the parts it would look like this..

[
    {
        "id": 1,
        "description": "Tesla Model X",
        "car_parts": [
            {
                "id": 3,
                "description": "Tesla Engine",
                "is_car_part": true,
                "car_id": 1,
            }
        ],
    },

    {
        "id": 2,
        "description": "Nissan Leaf",
        "car_parts": [
            {
                "id": 4,
                "description": "Nissan battery",
                "is_car_part": true,
                "car_id": 2,
            },
            
            {
                "id": 5,
                "description": "Nissan lights",
                "is_car_part": true,
                "car_id": 2,
            },
        ],
    },
    
    {
        "id": 3,
        "description": "Tesla Engine",
        "is_car_part": true,
        "car_id": 1,
    },
    
    {
        "id": 4,
        "description": "Nissan battery",
        "is_car_part": true,
        "car_id": 2,
    },
    
    {
        "id": 5,
        "description": "Nissan lights",
        "is_car_part": true,
        "car_id": 2,
    },
]
Jul
06
4 weeks ago
Activity icon

Awarded Best Reply on There Is No Existing Directory At "/home/martin/4evergaming.com/storage/logs" And Its Not Buildable: Permission Denied

@snapey Good news! I was able to do without ssh access but I had to manually change /bootstrap/cache/config.php file and it worked

I just replaced this line

/home/martin/4evergaming.com/

with this line

/home/4evergaming/public_html/4evergaming/

And also I had to change my database config.

Activity icon

Replied to There Is No Existing Directory At "/home/martin/4evergaming.com/storage/logs" And Its Not Buildable: Permission Denied

@snapey Good news! I was able to do without ssh access but I had to manually change /bootstrap/cache/config.php file and it worked

I just replaced this line

/home/martin/4evergaming.com/

with this line

/home/4evergaming/public_html/4evergaming/

And also I had to change my database config.

Activity icon

Started a new Conversation There Is No Existing Directory At "/home/martin/4evergaming.com/storage/logs" And Its Not Buildable: Permission Denied

I have installed a Laravel app on my local computer and now I am trying to move it to a shared hosting (without ssh access). But I'm getting this error

There is no existing directory at "/home/martin/4evergaming.com/storage/logs" and its not buildable: Permission denied

What does it mean? How could I fix it?

The new directory on my shared host is this

/home/4evergaming/public_html/4evergaming/
Jun
16
1 month ago
Activity icon

Started a new Conversation How To Refactor A Large Function Into A Smaller One?

I am learning about clean and maintainable code. I heard that functions should be no more than 20 lines long (preferably 5 - 10 lines). I have come across this Bob Martin quote where he said:

“The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that”.

And also this one

“Functions should do one thing. They should do it well. They should do it only”.

This all sounds great in theory but when a new programmer starts out - their code looks nothing like the above. And I'm not sure how to start to refactor this function to be small and do only one thing.

This function is taken from my Cash Register app that I'm making using Vue.js + Laravel. When a user clicks on the green "Pay" button - there are many things that need to happen so how can my function still be small?

<button @click="processPayment('cash')">Pay</button>

  1. Check if a user has ordered a regular sandwich and show a notification to offer a special sandwitch.
  2. Give some "special" tables a discount
  3. Validate if there are any items selected
  4. If there has been a discount, check if there is also a comment - else show an error
  5. Deal with Food Delivery services (special treatment)
  6. Call the Pay backend API
  7. Refresh all the data
  8. Call the Print Receipt API
  9. Start Table Timers (so we know how long the customer has been waiting for their order)
  10. Play the new order sound (ding!)
  11. Reset everything at the end

Whoa! That's a lot of things going on there when the Pay button is pressed. How can we possibly make this function do only one thing and be short? I'm confused.

Here is my long method:

async processPayment(payment_method, options = null)
{
    this.checkIfOrderContainsRegularSandwitch()

    if (store.orderContainsRegularSandwitch && !store.isConfirmedOrder) {
        store.showOrderConfirmationModal = true
        return
    }

    // comment for special tables
    if (this.specialTableSelected()) {
        store.orderComment = store.pickedTable.description
    }

    /**
     * discounts for special tables
     */

    if (this.specialTableSelected() && payment_method != 'Uber' && payment_method != 'DoorDash') {
        Order.applySpecialTableDiscounts()
    }


    if (!store.orderedItems.length) {
        CashRegister.reset()
        return
    }

    if (store.order.discount > 0 && !store.orderComment) {
        if (payment_method != 'Uber' && payment_method != 'DoorDash' ) {
            store.infoModalTitle = this.lang('order_with_discount')
            store.infoModalMessage = this.lang('order_with_discount_msg')
            store.showInfoModal = true

            return;
        }
    }

    if (payment_method == 'Uber') {
        store.isUber = true
        store.orderComment = 'Uber'
    }

    if (payment_method == 'DoorDash') {
        store.isDoorDash = true
        store.orderComment = 'DoorDash'
    }

    // 30% discount for Uber or DoorDash
    if (payment_method == 'Uber' || payment_method == 'DoorDash') {
        store.orderDiscount = 30
        store.orderDiscountType = '%'

        Order.applyTotalDiscount()
        Order.calculateTotals()
    }

    if (!store.order.isPaid)
    {
        store.isPaymentLoading = true

        // Save the order
        let order_id = await OrderApi.pay({
            order:          store.order,
            orderedItems:   store.orderedItems,
            payment_method: payment_method,
            table:          store.pickedTable.description,
            table_id:       store.pickedTable.id,
            order_mode:     store.orderMode,
            order_comment:  store.orderComment,
            takeaway_time : store.takeawayTime,
            is_takeaway:    (store.isTakeaway) ? 1 : 0,
            ml_delivery_phone:  store.MLDeliveryPhone,
            is_ml_delivery:    (store.isMLDelivery) ? 1 : 0,
            applied_discount: store.orderDiscount,
            applied_discount_type: store.orderDiscountType,
            has_coupon: store.hasCoupon,
            pay_cash: options?.pay_cash ?? 0,
            pay_card: options?.pay_card ?? 0,
        })

        order_id = order_id.data

        store.isPaymentLoading = false


        // Refresh order history
		OrderHistory.getTotalOrderHistory({
			date: moment().format('YYYY-MM-DD'),
		})


        // Refresh tables
        Data.getTables().then(({ data }) => {
            store.tables = data
        })


        // Refresh popular today
        Data.getPopularToday().then(({ data }) => {
            store.popularToday = data
        })


        // Print receipt
        if (store.shouldPrint) {
            await this.printReceipt({})
        }

        // Refresh Bar Items
        Data.getBarItems().then(({ data }) => {
            store.barItems = data

            if (store.barItems.length) {
                store.isBarCarouselMinimized = false
            }
        })

        if (payment_method != 'Uber' && payment_method != 'DoorDash') {
            if (store.order.payment_method != 'Pay later') {
                if (store.settings.settings?.table_timers == true) {
                    this.startTableTimer(store.pickedTable.id, order_id, 0)
                }
            }
        }

        if (store.settings.settings.new_order_notification_sound) {
            this.playNewOrderSound(store.orderedItems)
        }

        CashRegister.reset(order_id)
    }
},
May
14
2 months ago
Activity icon

Replied to How To Get Only One KeyBy Value Instead?

@nakov Perfect, that's exactly what I was looking for! Thank you!

Activity icon

Started a new Conversation How To Get Only One KeyBy Value Instead?

I have this settings table where I have key and value columns

+----+----------+-------------+
| id | key      | value       |
+----+----------+-------------+
| 1  | logo_img | my-logo.jpg |
| 2  | version  | 1.1         |
+----+----------+-------------+

and I would like to get the results like this.

"settings": {
  "logo_img": "my-logo.jpg",
  "version": 1.1,
}

But instead I get the results like this if I use keyBy()

$settings = Settings::all()->keyBy('key');

Results:

"settings": {
  "logo_img": {
    "id": 1,
    "key": "logo_img",
    "value": "my-logo.jpg"
  },

  "version": {
    "id": 2,
    "key": "version",
    "value": "1.1"
  }
}

In the end I would like to refer to settings like this $settings->logo_img instead of $settings->logo_img->value

Not sure how to do this

Apr
21
3 months ago
Activity icon

Replied to How To Have Multiple Domains For COOKIE Session?

@tippin Thank you, overriding config at runtime is brilliant! I will give this a try.

Activity icon

Started a new Conversation How To Have Multiple Domains For COOKIE Session?

My application can be accessed using 2 different domain names www.4evergaming.com and www.best4games.com

Here is how my routes file looks like

Route::pattern('domain', '(www.4evergaming.com|www.best4games.com)');
Route::domain('{domain}')->group(function ()
{
	// Routes here...
})

But in my config/session.php I can only have one domain...

'domain' => '.4evergaming.com',

I need to set session cookies for both domains but how can I do this?

Apr
08
3 months ago
Activity icon

Replied to Someone Told Me That A Laravel App Is Difficult To Maintain, Is It True?

@tray2 I agree that a lot of it depends on the developer. Do you think it could be an issue if the code base gets very large?

Activity icon

Started a new Conversation Someone Told Me That A Laravel App Is Difficult To Maintain, Is It True?

A friend of mine (business man, not a programmer) told me that Laravel applications are difficult to maintain. Specifically their codebase as it gets very large. That's why he prefers to use Symphony framework instead.

What do you think about this? Is it true? What are your thoughts on this?

Mar
03
5 months ago
Activity icon

Started a new Conversation How To Separate Node.js App Into 2 Different Files?

I have a simple Node.js app. But I would like to extract one part of it into another file but I don't know how to do this.

Here is my app

const fs = require('fs')
const https = require('https')
const express = require('express')

const app = express()

const server = https.createServer({
    cert: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/cert.pem'),
    key: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/privkey.pem'),
}, app)


server.listen(443)

I would like to put this part into a file certificate.js and include it in my main app.js file

certificate.js

const server = https.createServer({
    cert: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/cert.pem'),
    key: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/privkey.pem'),
}, app)

I would appreciate some help on this...