Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

MyLibrary

Experience

2,080

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 13 Lessons Completed
  • 0 Favorites

2nd July, 2017

MyLibrary left a reply on Set An Attribute Only For Newly Created Models? (Only For Creation, Not Update) • 5 months ago

I can do as the following code:

/**
     * Save a new model and return the instance.
     *
     * @param  array $attributes
     *
     * @return static
     */
    public static function create(array $attributes = [])
    {
        parent::create($attributes + ['reference' => GeneratorHelpers::generateUniqueId('SH')]);
    }

However, I wonder if there is a better practice or more acceptable way?

MyLibrary left a reply on Set An Attribute Only For Newly Created Models? (Only For Creation, Not Update) • 5 months ago

Yes, I can do it, the thing is I create a new model in many different places, and I would prefer not return the code if I can keep all in one place, the code I'm using right now:

Shipment::create(
                        $request->all() + [
                            'reference' => GeneratorHelpers::generateUniqueId('SH')
                        ]
);

MyLibrary started a new conversation Set An Attribute Only For Newly Created Models? (Only For Creation, Not Update) • 5 months ago

Heya guys,

I would like to set a reference code to each newly created model. A mutator won't help in this case.

Thanks for your advice!

26th June, 2017

MyLibrary started a new conversation Best Practice For Settings Table In Database And How To Implement In Laravel? • 5 months ago

Hey guys, What is the ideal way to create a settings table? should the settings be the columns of the table and the values should be the settings data or perhaps I should create a settings table with 2 columns "name" and "data" so I can get each settings by:

Settings::where('name', 'settingName')

Thanks for your help guys!

17th June, 2017

MyLibrary left a reply on Replacing A Place Holder {placeholder} With A Variable $placeholder? • 6 months ago

Hey @lars6 I meant replace a placeholder in expression with a variable, for example:

2*{placeholder}+10 which stored as a string in the database, and in practice I would like the script to run it as:

2*$placeholder+10.

Thanks a lot! =)

16th June, 2017

MyLibrary started a new conversation Replacing A Place Holder {placeholder} With A Variable $placeholder? • 6 months ago

Hey guys, I wonder, for example, if I save the pattern such as {placeholder} in database, and would like to replace it with $placeholder, what is gonna be the best practice?

Thanks guys!

14th June, 2017

MyLibrary left a reply on Ideal Way To Generate A Unique Reference Code? • 6 months ago

@cawex, I can use a validation to check if it unique, otherwise creating a new uniqid(). The prefix suggestion will create different size reference code with time, and I would prefer to keep it at the same length at this moment.

@Talky, that idea might work, but bcrypt generates a long reference code.

I wonder if there is something not too short and not too long that will include the microtime, the model type (for example order) and the model id, and then make a unique string out of that, what do you think guys?

At this moment I'm using: ** strtoupper(uniqid('OR')) // OR stands for Orders prefix. **

Thanks for your help guys!

MyLibrary left a reply on Ideal Way To Generate A Unique Reference Code? • 6 months ago

@cawex, It does have also a regular Id (incremental Id) but also need a reference id.

That looks nice, but might need something a bit shorter. I've used the uniqid() function, do you think it is strong enough guys?

MyLibrary left a reply on Ideal Way To Generate A Unique Reference Code? • 6 months ago

Hey @Snapey , Yes, I absolutely can, but I need the reference code to be something unique so I can also use in external platforms. (External service providers such as shipping carriers and so on).

Thanks!

12th June, 2017

MyLibrary started a new conversation Ideal Way To Generate A Unique Reference Code? • 6 months ago

Hey guys, I would like to generate a unique reference code in my system for Orders, Procurement and Transactions. Do you have any suggestions how big should be the reference code and how should I implement it in an efficient way? The system should have xxx procurement per year, xxxx orders per year and about xxxx transactions per year.

Thanks for your help!

8th May, 2017

MyLibrary left a reply on Terminal Bus & Commands In Laravel 5.2? • 7 months ago

Any help?

7th May, 2017

MyLibrary started a new conversation Terminal Bus & Commands In Laravel 5.2? • 7 months ago

Heya guys, I've noticed that in Laravel 5.2 there's no such thing terminal bus (and commands generally), Can you advice me alternative architecture on Laravel 5.2?

Thanks, Marco.

20th April, 2017

MyLibrary left a reply on Static "scope", May It Work Somehow? • 7 months ago

Any suggestions guys?

19th April, 2017

MyLibrary started a new conversation Static "scope", May It Work Somehow? • 7 months ago

Hey guys,

I've a Warehouse model and Product model which have ManyToMany relationship.

  1. Does it make sense to you? As I feel comfortable to say:

Product belongsToMany Warehouses But it is a bit odd to say Warehouse belongsToMany Products (As it make more sense to say Warehouse HasMany Products). Anyway, is that consider as a correct relationship?

  1. I have a static function in the Warehouse model, "scope" style which should return all non associated warehouses with a given product:
public static function nonAssociatedWith(Model $model, $foreignKey)
    {
        return static::whereDoesntHave($model->getTable(), function ($query) use ($model, $foreignKey)
        {
            $query->where($foreignKey, $model->id);
        });
    }

It get a Model, for example Product and a foreignKey which represent the column name in the pivot table and then return all of the non associated warehouses with the product.

Does it make sense to you guys? how would you improve it?

Thanks a lot!

17th April, 2017

MyLibrary left a reply on What Kind Of Relationship To Set Between Products And Warehouses? • 7 months ago

Thanks for your help guys!

topvillas this is a nice idea, but I can at the same time use basic HasMany and BelongToMany relationship, am I right?

I just wonder, I'm sure I can define: Warehouse hasMany products (does make sense).

But does it make sense that product is belongToMany relationship?

Anyway, would you advice to use the classic manyToMany, or hasManyThrough?

Thanks a lot.

MyLibrary left a reply on What Kind Of Relationship To Set Between Products And Warehouses? • 8 months ago

Yes I know I can use that convention, though I'm not sure how to record the stock quantity? Should I, for example, record 100 times the relationship if the quantity is 100?

MyLibrary started a new conversation What Kind Of Relationship To Set Between Products And Warehouses? • 8 months ago

Hey guys!

I'm building a system to manage stock and sales, and right now I'm working on the products and warehouses feature.

I've stock for every product, which located in the warehouse.

Right now I've set a new model "Stock" which has: product_id - References "id" on "products" table. warehouse_id - References "id" on "warehouses" table. quantity - the amount of available stock of a certain product in a certain warehouse.

I wonder if you have a good idea how to represent or implement it better?

As I can say, every "Warehouse" has many "Product"s, but I'm not sure if I can define "Product" to be belong to "Warehouse".

Let me know if you have a better idea guys!

25th September, 2016

MyLibrary left a reply on Pagination With Existing Paramethers In The URL? • 1 year ago

Perfect Matt! I appreciate your kind help! (should have read it by my self, somehow missed that section =} )

Thanks for your kind help!

MyLibrary left a reply on Pagination With Existing Paramethers In The URL? • 1 year ago

links() method is not supported in Laravel 5.0.

MyLibrary started a new conversation Pagination With Existing Paramethers In The URL? • 1 year ago

I know my threads subjects may confuse some of you, but let me explain a bit better:

I've the resourceful route:

Route::resource('deposits', 'DepositsController');

So in order to show all deposits I ofcurse visit the URI: url.com/deposits

And at the bottom I've the pagination feature (using "render"), that redirect to the deisred page, for instance: url.com/deposits?page=2

So far, all good, now lets take it a bit further, I've built a sorting feature that look for attributes in the URI and sorting the results accordingly, so for example:

url.com/deposits?employee=1&flag=&deposit_type=&documents=&client_name=&phone=&comment=&id=&amount_from=&amount_to=&datePicker=&amount=&creation_date=

Will display records according to the attributes, so far, again, it's all good!

The problem starts when the there are more than 10 records (which I've defined this amount earlier) it still redirect to: url.com/deposits?page=2 Instead of `` url.com/deposits?employee=1&flag=&deposit_type=&documents=&client_name=&phone=&comment=&id=&amount_from=&amount_to=&datePicker=&amount=&creation_date=&page=2


And this is how the deposits sorting is written:

$deposits = Deposit::filterBy( [ 'id' => urlParamOrNull('id'), 'employee_id' => urlParamOrNull('employee'), 'type_id' => urlParamOrNull('deposit_type'), 'amount' => urlParamOrNull('amount'), 'amountOperator' => urlParamOrNull('amount_operator'), 'flag_id' => urlParamOrNull('flag'), 'comment' => urlParamOrNull('comment'), 'client_name' => urlParamOrNull('client_name'), 'phone' => urlParamOrNull('phone'), 'documents' => urlParamOrNull('documents'), 'created_at' => urlParamOrNull('creation_date'), ]) ->orderBy('created_at', 'desc') ->paginate($this->recordsPerPage);


Can you please try to help me our? how can I define that the paginate will add the page attribute to the end of the URI and won't change it completely to the actual route path + the page number?

Thanks once again!

11th September, 2016

MyLibrary left a reply on Best Architecture To Build Plural Model Methods? • 1 year ago

Great, that scope is what I was looking for.

Thanks a lot mate!

MyLibrary started a new conversation Best Architecture To Build Plural Model Methods? • 1 year ago

I know the title may mislead, but let me try to explain my point.

Lets assume that I have the model 'Deposit' and its related controller - 'DepositsController'. In another controller I would like to fetch all deposits within specific date range - lets say from X to Y.

The model 'Deposits' as I understand, is designated to constitute a layer between the DB and the controller, and it is mostly in a single form and not plural - for example:

Model::find();
Model::create();

And at this moment I do have a method in the Model:

public static function currentWeek()
    {
        return static::where('created_at', '>=', Carbon::now()->startOfWeek())
                     ->where('created_at', '<=', Carbon::now()->endOfWeek());
    }

And then I call it statically to fetch all deposits.

What is the best way to implement that in OOP and MVC way? Do you have some specific pattern for such tasks? do you set those in the controller and then instanitate the DepositsController in the OtherController consturctor as $this->deposits field?

Will be happy to get your valued opinion??

22nd August, 2016

MyLibrary left a reply on "Missing Argument 2" Error In Collection Filter Function • 1 year ago

Hey Zach, I got the following error:

1/1
ErrorException in UpdateSwapsUSD.php line 36:
Missing argument 2 for App\Commands\UpdateSwapsUSD::App\Commands\{closure}()

And in the code:

$filtered = $swaps->filter(function ($value, $key)
 {
            
});

MyLibrary left a reply on "Missing Argument 2" Error In Collection Filter Function • 1 year ago

Hey Zach, It doesn't really matter, I've added the third argument after using 2 arguments never worked.

Any other toughts?

MyLibrary left a reply on "Missing Argument 2" Error In Collection Filter Function • 1 year ago

In the documentation I can't find anything regard second argument, see for example from Laravel documentation section:

$collection = collect(['taylor', 'abigail', null])->map(function($name)
{
    return strtoupper($name);
})

Where is the second argument over here?

Thanks!

MyLibrary started a new conversation "Missing Argument 2" Error In Collection Filter Function • 1 year ago

Hey guys, I'm getting the following error:

Missing argument 2 for App\Commands\UpdateSwapsUSD::App\Commands\{closure}()

And the part of code which arise this error is:

$filtered = $swaps->filter(function ($value, $key, $do)
        {

        });

Can you please tell me what I'm doing wrong?

8th August, 2016

MyLibrary started a new conversation Good Example Of Using Command Pipeline? • 1 year ago

Hey guys, I hope you're all doing fine!

Will be happy to understand a bit more when will you consider to use a pipeline and actually how? In laravel 5.0 Documentation I can find the following example:

$dispatcher->pipeThrough(['UseDatabaseTransactions', 'LogCommand']);

Now I understand it will pipe the command through those commands as well, but... as Laravel documentation doesn't show how the methods above built, I find it harder to understand.

I understand that if for example I've some command, I set properties and can use them in the methods in the "pipeline", but can you share with me a real example of using this great feature? maybe try to demonstate the LogCommand for learning purposes?

Kind regard, Marco.

4th August, 2016

MyLibrary left a reply on Best Place For Function To "fetch" Statistics (Model / Controller) • 1 year ago

Even though when

Employee::getTodayEmployeesDeposits

Fetch results for many employees (for all employees) and not only for 1 Employee? Is that still the right way to do it?

Thanks!

MyLibrary started a new conversation Best Place For Function To "fetch" Statistics (Model / Controller) • 1 year ago

Hey friends,

I would like to set a some methods which I'm not sure where should be their placements, for example:

EmployeesController::bestDealerOfTheWeek

Or

Employee::bestDealerOfTheWeek
EmployeesController::getTodayEmployeesDeposits

Or

Employee::getTodayEmployeesDeposits

Or should I just place it in a different kind of class?

Kind regard, Marco.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.