D
D
dmytrotus2019-09-15 01:02:00
Laravel
dmytrotus, 2019-09-15 01:02:00

How to extend vendor class in Laravel?

Good evening. I really want to understand the topic of Service Container in Laravel, but after reading the documentation I can’t understand anything.
If someone can help me solve the problem I would be very grateful.
My assignment is this.
There is a project on Laravel 6.0
There is a bumbummen99/shoppingcart package.
The container that is responsible for all the logic of the package is located here
vendor\bumbummen99\shoppingcart\src\Cart.php
Inside the file is the following content

<?php
namespace Gloudemans\Shoppingcart;

class Cart
{
    const DEFAULT_INSTANCE = 'default';

    public function myNewFunction()
    {
        return 'My Test Function';
    }
}

myNewFunction is a function I created.
I call it now anywhere with the help
Cart->myNewFunction()
Everything works, but there is a problem. When I update the composer,
composer update
the package is updated and the function is overwritten.
If anyone can, please explain how to put the myNewFunction () method, for example, into a folder
app\http\binding\
. As I understand it, you can make a container that will inherit Cart.
The idea is to change the functionality of the files that are in the vendor and so that they are not overwritten.
To be something like.
class MyBindingClass extends Cart
{
    public function myNewFunction()
    {
        return 'My Test Function';
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2019-09-15
@dmytrotus

$this->app->bind('cart', app\http\binding\MyBindingClass::class);

Guess where to put it? If not, then you need to read the documentation further, perhaps in Russian.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question