If you grew up any time in the 1980s or early 1990s, you’ll appreciate this epic compilation of commercials from the era. K. Huntington dug up many of these clips from old Betamax tapes a few years back. Even if you don’t have four hours to kill, it’s worth skipping around a bit to check out some random retro goodness.
Dark Empire: Episode 1
The first episode of animator Ian Wilkins‘ Star Wars fan series is here, and it’s every bit as good as we hoped it would be. Many years after the fall of Vader and the Emperor at Endor, remaining members of the Rebel Alliance must once again defend against the Empire as they regain strength against the New Republic.
bumbummen99/shoppingcart
LaravelShoppingcart
This is a fork of Crisane’s LaravelShoppingcart extended with minor features compatible with Laravel 6.
Installation
Install the package through Composer.
Run the Composer require command from the Terminal:
composer require bumbummen99/shoppingcart
Now you’re ready to start using the shoppingcart in your application.
As of version 2 of this package it’s possibly to use dependency injection to inject an instance of the Cart class into your controller or other class
Overview
Look at one of the following topics to learn more about LaravelShoppingcart
Usage
The shoppingcart gives you the following methods to use:
Cart::add()
Adding an item to the cart is really simple, you just use the add() method, which accepts a variety of parameters.
In its most basic form you can specify the id, name, quantity, price and weight of the product you’d like to add to the cart.
Cart::add('293ad', 'Product 1', 1, 9.99, 550);
As an optional fifth parameter you can pass it options, so you can add multiple items with the same id, but with (for instance) a different size.
Cart::add('293ad', 'Product 1', 1, 9.99, 550, ['size' => 'large']);
The add() method will return an CartItem instance of the item you just added to the cart.
Maybe you prefer to add the item using an array? As long as the array contains the required keys, you can pass it to the method. The options key is optional.
Cart::add(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'weight' => 550, 'options' => ['size' => 'large']]);
New in version 2 of the package is the possibility to work with the Buyable interface. The way this works is that you have a model implement the Buyable interface, which will make you implement a few methods so the package knows how to get the id, name and price from your model. This way you can just pass the add() method a model and the quantity and it will automatically add it to the cart.
As an added bonus it will automatically associate the model with the CartItem
Cart::add($product, 1, ['size' => 'large']);
As an optional third parameter you can add options.
Cart::add($product, 1, ['size' => 'large']);
Finally, you can also add multipe items to the cart at once. You can just pass the add() method an array of arrays, or an array of Buyables and they will be added to the cart.
When adding multiple items to the cart, the add() method will return an array of CartItems.
Cart::add([ ['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 10.00, 'weight' => 550], ['id' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'weight' => 550, 'options' => ['size' => 'large']] ]); Cart::add([$product1, $product2]);
Cart::update()
To update an item in the cart, you’ll first need the rowId of the item. Next you can use the update() method to update it.
If you simply want to update the quantity, you’ll pass the update method the rowId and the new quantity:
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; Cart::update($rowId, 2); // Will update the quantity
If you want to update more attributes of the item, you can either pass the update method an array or a Buyable as the second parameter. This way you can update all information of the item with the given rowId.
Cart::update($rowId, ['name' => 'Product 1']); // Will update the name Cart::update($rowId, $product); // Will update the id, name and price
Cart::remove()
To remove an item for the cart, you’ll again need the rowId. This rowId you simply pass to the remove() method and it will remove the item from the cart.
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; Cart::remove($rowId);
Cart::get()
If you want to get an item from the cart using its rowId, you can simply call the get() method on the cart and pass it the rowId.
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; Cart::get($rowId);
Cart::content()
Of course you also want to get the carts content. This is where you’ll use the content method. This method will return a Collection of CartItems which you can iterate over and show the content to your customers.
This method will return the content of the current cart instance, if you want the content of another instance, simply chain the calls.
Cart::instance('wishlist')->content();
Cart::destroy()
If you want to completely remove the content of a cart, you can call the destroy method on the cart. This will remove all CartItems from the cart for the current cart instance.
Cart::weight()
The weight() method can be used to get the weight total of all items in the cart, given there weight and quantity.
The method will automatically format the result, which you can tweak using the three optional parameters
Cart::weight($decimals, $decimalSeperator, $thousandSeperator);
You can set the default number format in the config file.
If you’re not using the Facade, but use dependency injection in your (for instance) Controller, you can also simply get the total property $cart->weight
Cart::total()
The total() method can be used to get the calculated total of all items in the cart, given there price and quantity.
The method will automatically format the result, which you can tweak using the three optional parameters
Cart::total($decimals, $decimalSeparator, $thousandSeparator);
You can set the default number format in the config file.
If you’re not using the Facade, but use dependency injection in your (for instance) Controller, you can also simply get the total property $cart->total
Cart::tax()
The tax() method can be used to get the calculated amount of tax for all items in the cart, given there price and quantity.
The method will automatically format the result, which you can tweak using the three optional parameters
Cart::tax($decimals, $decimalSeparator, $thousandSeparator);
You can set the default number format in the config file.
If you’re not using the Facade, but use dependency injection in your (for instance) Controller, you can also simply get the tax property $cart->tax
Cart::subtotal()
The subtotal() method can be used to get the total of all items in the cart, minus the total amount of tax.
The method will automatically format the result, which you can tweak using the three optional parameters
Cart::subtotal($decimals, $decimalSeparator, $thousandSeparator);
You can set the default number format in the config file.
If you’re not using the Facade, but use dependency injection in your (for instance) Controller, you can also simply get the subtotal property $cart->subtotal
Cart::discount()
The discount() method can be used to get the total discount of all items in the cart.
The method will automatically format the result, which you can tweak using the three optional parameters
Cart::discount($decimals, $decimalSeparator, $thousandSeparator);
You can set the default number format in the config file.
If you’re not using the Facade, but use dependency injection in your (for instance) Controller, you can also simply get the subtotal property $cart->discount
Cart::initial()
The initial() method can be used to get the total price of all items in the cart before discount.
The method will automatically format the result, which you can tweak using the three optional parameters
Cart::initial($decimals, $decimalSeparator, $thousandSeparator);
You can set the default number format in the config file.
If you’re not using the Facade, but use dependency injection in your (for instance) Controller, you can also simply get the subtotal property $cart->initial
Cart::count()
If you want to know how many items there are in your cart, you can use the count() method. This method will return the total number of items in the cart. So if you’ve added 2 books and 1 shirt, it will return 3 items.
Cart::count(); $cart->count();
Cart::search()
To find an item in the cart, you can use the search() method.
This method was changed on version 2
Behind the scenes, the method simply uses the filter method of the Laravel Collection class. This means you must pass it a Closure in which you’ll specify you search terms.
If you for instance want to find all items with an id of 1:
$cart->search(function ($cartItem, $rowId) { return $cartItem->id === 1; });
As you can see the Closure will receive two parameters. The first is the CartItem to perform the check against. The second parameter is the rowId of this CartItem.
The method will return a Collection containing all CartItems that where found
This way of searching gives you total control over the search process and gives you the ability to create very precise and specific searches.
Cart::setTax($rowId, $taxRate)
You can use the setTax() method to change the tax rate that applies to the CartItem. This will overwrite the value set in the config file.
Cart::setTax($rowId, 21); $cart->setTax($rowId, 21);
Cart::setGlobalTax($taxRate)
You can use the setGlobalTax() method to change the tax rate for all items in the cart. New items will receive the setGlobalTax as well.
Cart::setGlobalTax(21); $cart->setGlobalTax(21);
Cart::setGlobalDiscount($discountRate)
You can use the setGlobalDiscount() method to change the discount rate for all items in the cart. New items will receive the discount as well.
Cart::setGlobalDiscount(50); $cart->setGlobalDiscount(50);
Cart::setDiscount($rowId, $taxRate)
You can use the setDiscount() method to change the discount rate that applies a CartItem. Keep in mind that this value will be changed if you set the global discount for the Cart afterwards.
Cart::setDiscount($rowId, 21); $cart->setDiscount($rowId, 21);
Buyable
For the convenience of faster adding items to cart and their automatic association, your model has to implement the Buyable interface. You can use the CanBeBought trait to implement the required methods but keep in mind that these will use predefined fields on your model for the required values.
<?php namespace App\Models; use Gloudemans\Shoppingcart\Contracts\Buyable; use Illuminate\Database\Eloquent\Model; class Product extends Model implements Buyable { use Gloudemans\Shoppingcart\CanBeBought; }
If the trait does not work for on the model or you wan’t to map the fields manually the model has to implement the Buyable interface methods. To do so, it must implement such functions:
public function getBuyableIdentifier(){ return $this->id; } public function getBuyableDescription(){ return $this->name; } public function getBuyablePrice(){ return $this->price; } public function getBuyableWeight(){ return $this->weight; }
Example:
<?php namespace App\Models; use Gloudemans\Shoppingcart\Contracts\Buyable; use Illuminate\Database\Eloquent\Model; class Product extends Model implements Buyable { public function getBuyableIdentifier($options = null) { return $this->id; } public function getBuyableDescription($options = null) { return $this->name; } public function getBuyablePrice($options = null) { return $this->price; } }
Collections
On multiple instances the Cart will return to you a Collection. This is just a simple Laravel Collection, so all methods you can call on a Laravel Collection are also available on the result.
As an example, you can quicky get the number of unique products in a cart:
Cart::content()->count();
Or you can group the content by the id of the products:
Cart::content()->groupBy('id');
Instances
The packages supports multiple instances of the cart. The way this works is like this:
You can set the current instance of the cart by calling Cart::instance('newInstance'). From this moment, the active instance of the cart will be newInstance, so when you add, remove or get the content of the cart, you’re work with the newInstance instance of the cart. If you want to switch instances, you just call Cart::instance('otherInstance') again, and you’re working with the otherInstance again.
So a little example:
Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99, 550); // Get the content of the 'shopping' cart Cart::content(); Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, 550, ['size' => 'medium']); // Get the content of the 'wishlist' cart Cart::content(); // If you want to get the content of the 'shopping' cart again Cart::instance('shopping')->content(); // And the count of the 'wishlist' cart again Cart::instance('wishlist')->count();
You can also use the InstanceIdentifier Contract to extend a desired Model to assign / create a Cart instance for it. This also allows to directly set the global discount.
<?php namespace App; ... use Illuminate\Foundation\Auth\User as Authenticatable; use Gloudemans\Shoppingcart\Contracts\InstanceIdentifier; class User extends Authenticatable implements InstanceIdentifier { ... /** * Get the unique identifier to load the Cart from * * @return int|string */ public function getInstanceIdentifier($options = null) { return $this->email; } /** * Get the unique identifier to load the Cart from * * @return int|string */ public function getInstanceGlobalDiscount($options = null) { return $this->discountRate ?: 0; } } // Inside Controller $user = \Auth::user(); $cart = Cart::instance($user);
N.B. Keep in mind that the cart stays in the last set instance for as long as you don’t set a different one during script execution.
N.B.2 The default cart instance is called default, so when you’re not using instances,Cart::content(); is the same as Cart::instance('default')->content().
Models
Because it can be very convenient to be able to directly access a model from a CartItem is it possible to associate a model with the items in the cart. Let’s say you have a Product model in your application. With the associate() method, you can tell the cart that an item in the cart, is associated to the Product model.
That way you can access your model right from the CartItem!
The model can be accessed via the model property on the CartItem.
If your model implements the Buyable interface and you used your model to add the item to the cart, it will associate automatically.
Here is an example:
// First we'll add the item to the cart. $cartItem = Cart::add('293ad', 'Product 1', 1, 9.99, 550, ['size' => 'large']); // Next we associate a model with the item. Cart::associate($cartItem->rowId, 'Product'); // Or even easier, call the associate method on the CartItem! $cartItem->associate('Product'); // You can even make it a one-liner Cart::add('293ad', 'Product 1', 1, 9.99, 550, ['size' => 'large'])->associate('Product'); // Now, when iterating over the content of the cart, you can access the model. foreach(Cart::content() as $row) { echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.'; }
Database
Configuration
To save cart into the database so you can retrieve it later, the package needs to know which database connection to use and what the name of the table is. By default the package will use the default database connection and use a table named shoppingcart. If you want to change these options, you’ll have to publish the config file.
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="config"
This will give you a cart.php config file in which you can make the changes.
To make your life easy, the package also includes a ready to use migration which you can publish by running:
php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="migrations"
This will place a shoppingcart table’s migration file into database/migrations directory. Now all you have to do is run php artisan migrate to migrate your database.
Storing the cart
To store your cart instance into the database, you have to call the store($identifier) method. Where $identifier is a random key, for instance the id or username of the user.
Cart::store('username'); // To store a cart instance named 'wishlist' Cart::instance('wishlist')->store('username');
Restoring the cart
If you want to retrieve the cart from the database and restore it, all you have to do is call the restore($identifier) where $identifier is the key you specified for the store method.
Cart::restore('username'); // To restore a cart instance named 'wishlist' Cart::instance('wishlist')->restore('username');
Merge the cart
If you want to merge the cart with another one from the database, all you have to do is call the merge($identifier) where $identifier is the key you specified for the store method. You can also define if you want to keep the discount and tax rates of the items.
// Merge the contents of 'savedcart' into 'username'. Cart::instance('username')->merge('savedcart', $keepDiscount, $keepTaxrate);
Exceptions
The Cart package will throw exceptions if something goes wrong. This way it’s easier to debug your code using the Cart package or to handle the error based on the type of exceptions. The Cart packages can throw the following exceptions:
| Exception | Reason |
|---|---|
| CartAlreadyStoredException | When trying to store a cart that was already stored using the specified identifier |
| InvalidRowIDException | When the rowId that got passed doesn’t exists in the current cart instance |
| UnknownModelException | When you try to associate an none existing model to a CartItem. |
Events
The cart also has events build in. There are five events available for you to listen for.
| Event | Fired | Parameter |
|---|---|---|
| cart.added | When an item was added to the cart. | The CartItem that was added. |
| cart.updated | When an item in the cart was updated. | The CartItem that was updated. |
| cart.removed | When an item is removed from the cart. | The CartItem that was removed. |
| cart.stored | When the content of a cart was stored. | – |
| cart.restored | When the content of a cart was restored. | – |
Example
Below is a little example of how to list the cart content in a table:
// Add some items in your Controller. Cart::add('192ao12', 'Product 1', 1, 9.99); Cart::add('1239ad0', 'Product 2', 2, 5.95, ['size' => 'large']); // Display the content in a View. <table> <thead> <tr> <th>Product</th> <th>Qty</th> <th>Price</th> <th>Subtotal</th> </tr> </thead> <tbody> <?php foreach(Cart::content() as $row) :?> <tr> <td> <p><strong><?php echo $row->name; ?></strong></p> <p><?php echo ($row->options->has('size') ? $row->options->size : ''); ?></p> </td> <td><input type="text" value="<?php echo $row->qty; ?>"></td> <td>$<?php echo $row->price; ?></td> <td>$<?php echo $row->total; ?></td> </tr> <?php endforeach;?> </tbody> <tfoot> <tr> <td colspan="2"> </td> <td>Subtotal</td> <td><?php echo Cart::subtotal(); ?></td> </tr> <tr> <td colspan="2"> </td> <td>Tax</td> <td><?php echo Cart::tax(); ?></td> </tr> <tr> <td colspan="2"> </td> <td>Total</td> <td><?php echo Cart::total(); ?></td> </tr> </tfoot> </table>
Metatags
Metatags
A Laravel package to fetch all metadata of a webpage.
Installation
Perform the following operations in order to use this package
-
Run
composer require "mobiosolutions/metatags"in your terminal -
Add Service Provider Open
config/app.phpand addmobiosolutions\metatags\Providers\MetatagsProvider::class,to the end ofprovidersarray:'providers' => array( .... mobiosolutions\metatags\Providers\MetatagsProvider::class, ),Next under the
aliasesarray:'aliases' => array( .... 'Metatags' => mobiosolutions\metatags\Facades\MetatagsFacade::class ),
Requirements
- You need to install the DOM extension.
How to use
-
After following the above steps,
// Add to your controller to get all metatags data use Metatags; $metadata = Metatags::get("https://example.com/"); print_r($metadata);Get only OG ( Open Graph ) Metatages data
$getOGTags = true; $metadata = Metatags::get("https://example.com/",$getOGTags); OR $metadata = Metatags::get("https://example.com/",true); print_r($metadata);
8 Tools & Tips to Deliver Laravel Projects Quicker
Have you ever been late on a project delivery? Yeah, I know that stress feeling. At QuickAdminPanel, we see our mission as helping developers to deliver projects quicker. There are many ways to save valuable hours, generating or reusing existing code instead of writing it from scratch. In this article, I will share the tools and processes that helped me in my own Laravel developer journey, to deliver quicker.
via Laravel News Links
8 Tools & Tips to Deliver Laravel Projects Quicker
Laravel Initializer 2.0 – a convenient way to initialize your application
This commit was created on GitHub.com and signed with a verified signature using GitHub’s key.
It’s major release with code polishing, beautified output and several nice features.
app:install and app:update commands output now much more expressive. You can check out new output in the README demo. Made with nunomaduro/laravel-console-task.
- Commands output are hidden by default
- Output details of execution could be viewed in verbosity mode
- Ability to publish multiple tags for one provider
- Ability to publish by tags only
- Replaced
make:initializerscommand by publishinginitializerstag - Updated default initializer stubs
You can’t perform that action at this time.
via Laravel News Links
Laravel Initializer 2.0 – a convenient way to initialize your application
Mighty Carver Chainsaw Knife
Family stressing you out at holiday gatherings? Lighten the mood this year when you go to cut the turkey with a chainsaw. While an actual chainsaw would be entertaining, we’d suggest the Mighty Carver, an electric carving knife which won’t end up destroying the bird or your dining table.


A REST Client Inside Your Laravel Projects
A REST Client Inside Your Laravel Projects
Laravel Compass is a package by David H. Sianturi providing a REST client inside your Laravel project:
Laravel Compass is an elegant REST assistant for the Laravel framework that you can use to test API calls and create API documentation. It provides endpoints automatically for GET, POST, PUT/PATCH, DELETE, various auth mechanisms, and other utility endpoints based on Laravel routes in your project.
Compass provides an SPA backend experience with your routes preloaded. That’s right, compass will automatically provide endpoints based on Laravel route definitions. If you’ve ever used Postman, the Laravel Compass UI will feel familiar:
You can learn more about this package, get full installation instructions, and view the source code on GitHub at davidhsianturi/laravel-compass.
Enjoy this? Get Laravel News delivered straight to your inbox every Sunday.
No Spam, ever. We’ll never share your email address and you can opt out at any time.
Best Practices to Secure Your MySQL Databases
Author: Robert Agar
MySQL is one of the most popular database platforms in the world. It is widely used to power eCommerce sites and web applications that are essential components of many companies’ business strategies. MySQL databases are often the repository for sensitive customer data gathered while conducting business as well as information regarding internal processes and personnel.
An organization’s databases are responsible for storing and manipulating the information required to keep it operating and competing effectively in their market. They are critically important to a company’s success and need to be guarded and kept secure. The database team comprises an enterprise’s first line of defense and is responsible for implementing security policies and standards that minimize the chances for the systems to be accessed by unauthorized users or exposed to malicious malware.
One of the challenges facing DBAs is the proliferation of multiple-platform environments that they are expected to successfully manage. While some security measures are transferable between competing databases, there are variations that can make securing their systems challenging when bouncing from platform to platform. Let’s take a look at some of the steps a MySQL DBA should be taking to ensure the security of their databases.
Hardening the Database
Hardening a computer system is a means of protecting it from risks and threats with a multi-layered approach. Each layer, such as the host, application, user, and physical requires different methods to ensure security. Here are some specific steps to take that will harden your MySQL server. When modifying the my.cnf file, you will need to restart MySQL for the changes to be implemented.
Encrypting connections – MySQL network connections are not encrypted by default. This needlessly exposes your data and should be addressed by enforcing network connection encryption.
Setting a connection error limit – Multiple unsuccessful authentications may indicate an attack by unauthorized users. Allowing for a reasonable number of incorrect attempts can be done with the max_connect_errors parameter in the my.cnf file.
Disable the SHOW DATABASES command – This command can be used by attackers to identify the available databases in preparation for an attack. You can disable the command by inserting the skip-show-database line to the mysqld section of the configuration file.
Run the MySQL hardening script – Running the hardening script included with MySQL will lead you through a series of questions that help you set the level of hardening for your system. Execute the script with the mysql_secure_installation command.
Additional Security Measures
While the steps outlined above to harden your MySQL systems are an important start, there are many other ways to strengthen the security of your databases. Here are some of them.
Change the default port and account – By default, MySQL runs on port 3306 using the superuser “root” account. The default port should be changed in the configuration file to make your database less susceptible to random cyberattacks. The recommended method of dealing with the root account is to create a new superuser account and to eliminate all root@ accounts.
Tightly control database access – Fewer is better when it comes to users permitted to access a database. Permissions should be managed using groups or roles and the minimum privileges required to do a job should be granted to any individual.
Auditing and monitoring database activity – This is an essential task that can alert you to a number of security violations or flaws. Monitoring can help identify compromised accounts or those conducting suspicious activities. Periodically auditing your systems will show if accounts have been created outside of the normal workflow, perhaps by a hacker.
Maintaining Secure MySQL Instances
SQL Diagnostic Manager for MySQL offers a platform from which you can monitor and audit your database instances to ensure they remain secure. It provides over 600 pre-built monitors with the ability to give you real-time insight into your system’s performance. Monitored data can be displayed in customizable dashboards making it easy to identify and address problems promptly.
Managing user access and finding problematic trends can be accomplished by focusing the information available through the tool’s audit log. It lets you quickly see failed logins and events as well as changes made to the database. The data gained from studying these logs can help you discover potential security flaws and better protect your systems and the critical data they contain. It’s a powerful tool that should be part of all MySQL DBAs software repertoire.
The post Best Practices to Secure Your MySQL Databases appeared first on Monyog Blog.
via Planet MySQL
Best Practices to Secure Your MySQL Databases
Many to Many Relationships With Linking Tables
Next up, we have the slightly more confusing "many to many" relationship type. To illustrate this, we’ll use the common example of articles and tags. As we’ll quickly realize, a third table is necessary in order to associate one article with many tags, and one tag with many articles.
Published on Oct 25th, 2019.



