Managing Planetscale DB schema with Laravel migrations

https://opengraph.githubassets.com/befba0664babbe9f75ce81cbf06a6d6fa5a0568724da50853489be1ce853f853/x7media/laravel-planetscale

LaravelPlanetScale

Latest Version on Packagist
Total Downloads

This package adds a php artisan pscale:migrate command to your Laravel app which can be used instead of the normal php artisan migrate command when using a PlanetScale database.

Installation

Via Composer

composer require x7media/laravel-planetscale

Configuration & Usage

  1. Login to your PlanetScale account and get your Service Token and Service Token ID from the organaization settings. Also take a note of your organization name and production branch name as well for the next steps.

  2. Add the following database level permissions to your Service Token for your app’s database:

    • create_branch – Create a database branch
    • delete_branch – Delete a database branch
    • connect_branch – Connect to, or create passwords and certificates for a database branch
    • create_deploy_request – Create a database deploy request
    • read_deploy_request – Read database deploy requests
  3. From the database settings screen on PlanetScale, click the checkmark to enable the “Automatically copy migration data” settings. Select “Laravel” from the migration framework dropdown and it should fill it “migrations” for the migration table name. Then save the database settings. This will allow migration status to be synced across PlanetScale database branches.

  4. Setup the following enviroment variables in your app with the appropriate values:

PLANETSCALE_ORGANIZATION=

PLANETSCALE_PRODUCTION_BRANCH=

PLANETSCALE_SERVICE_TOKEN_ID=

PLANETSCALE_SERVICE_TOKEN=

Additonally yuou’ll need to make sure your database name is set under:

DB_DATABASE=

OR

Optionally you can publish the config:

php artisan vendor:publish --tag=laravel-planetscale-config

Then customize the values in the config. NOTE: If you take this approach we STRONGLY RECOMMEND that you still use enviroment varibles or some other secrets storage at least for your service token and service token ID for security.

  1. Replase the php artisan migrate command in your deployment script or process with this:
php artisan pscale:migrate

NOTE: The pscale:migrate command supports the same options are Laravel’s built in migration command, and will pass those options along to it when it gets to that step in the process.

FAQ’s

Why is this necessary?

PlanetScale has alot of advantages when using it as your application’s production database. However it handles your database and schema migrations in a somewhat unusual way.

It uses branches for your database. A branch can be production or development. You’ll want to use a production branch for your app in production because that afford you extra features like automatic backups, however you cannot perform schema changes directly against a production branch. Instead you should create a new development branch based on your production branch and perform your schema changes on that than merge that back into your production branch just like you would do with your code in Git.

This package uses PlanetScale’s Public API to automate the process of creating a new development branch, connecting your app to the development branch, running your Laravel migrations on the development branch, merging that back into your production branch, and deleting the development branch.

Are there any notable limitations to PlanetScale’s branching?

Yes, there is one BIG caveat. That is branching and merging is for schema only. So you will need to seperate your schema migrations from your data migrations. Use this to run your schema migrations and run your data migrations seperatly against your production branch.

An alternative method is to demote your production branch back to a development branch, then you can mix schema and data migrations. Then when that is finished promote the branch back to a production branch. But that is currently a manaual process. I have however made a request with the PlanetScale team to make a slight change to their API that would allow this demote-promote process to be automated, and if that change is made I will update this package. However I ultimately have no control over if or when that will become possible.

Change log

Please see the changelog for more information on what has changed recently.

Testing

Contributing

Please see the contributing guidelines.

Security

If you discover any security related issues, please email info@x7media.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

Laravel News Links

Langdon Tactical Offers Completely Free Training Video Series

https://cdn.athlonoutdoors.com/wp-content/uploads/sites/6/2023/03/langdon-tactical-03.jpg

The importance of quality education and training when it comes to firearms ownership and operation is absolutely paramount. Many who are new to firearms feel it can be daunting and have a lot of questions. Particularly those who consider making everyday carry a part of their lifestyle. For this reason, we introduce Langdon Tactical and its video training series and comprehensive resource.

Langdon Tactical Change the Game

Quality, thorough, thoughtful, and well-designed training content to serve firearms owners across the full spectrum of experience is important. However, no single platform has truly hit the mark.

This is where Ernest and Aimee Langdon enter the scene with designs to change the game. They are the president and vice president of the renowned firearms customization outfit Langdon Tactical Technology (LTT).

The Backstory

Ernest’s background includes 12 years of active-duty service in the United States Marine Corps. Additionally, he has more than 30 years of competitive shooting experience. His competitive accolades include a Grand Master rating in USPSA (United States Practical Shooting Association). Likewise, he has accreditation as a Distinguished Master in IDPA (International Defensive Pistol Association). Finally, he has ten National Championships and two World Speed Shooting titles.

Aimee is a global business professional with more than 16 years of accomplished professional business development, sales, and marketing experience. She has podiumed three times at The Tactical Games—twice in first and once in second place at the 2021 Nationals. While leading Business Development and Operations for LTT, she trains at a grueling pace and is an energetic and dedicated mom.

Ernest and Aimee Langdon of Langdon Tactical.

This couple not only helms the day-to-day business at LTT but are also the masterminds and producers behind LTT Discover. LTT is renowned for customizing and converting exceptional stock firearms platforms into extraordinary competition-quality enhanced guns. LTT Discover is a groundbreaking firearms education and empowerment platform.

Free Video Series and Comprehensive Training Resource

As noted in the mission statement of the LTT Discover website, the completely free video series and comprehensive training resource is “…aimed at bringing forth great information and resources to better guide and educate those looking to own a firearm without intimidation or demanding perfection.”

The curriculum is guided, based on experience level and keynotes distilled from the unique backgrounds and perspectives of both Aimee and Ernest. Likewise, it draws insight and contributions from influential pillars and experts in the 2A community. As a result, the series serves as a very inclusive, welcoming, well-rounded resource.

I recently navigated the series and website myself. Having experience with what else is (and isn’t) out there, I feel LTT Discover is genuinely a refreshing new approach. Even the most well-trained and experienced in the firearms community should find great value throughout.

Screenshot of Ernest Langdon providing firearm instruction in LTT Discover video.

I recently had a chance to chat with the founders about their journey together. We discussed the inception of the LTT Discover platform and learned what is in store for the community. Specifically as it applies to the future of firearms education and training.

QUESTIONS & ANSWERS

How did you two meet each other?

AIMEE: We worked together at a robotics company for six years. We both started new chapters personally and professionally and found each other romantically.

What’s life like between the business, family, and training? How do you juggle it all?

ERNEST: Balance. We are constantly balancing family time, work time, and personal time and sometimes we fail all the way around. But fitness and nutrition are pivotal components of our family unit. We are active together and love to cook.

AIMEE: Outside of our personal shooting training, we attend other classes and courses with other instructors to continue to learn from other people.

I understand the Discover platform was partially developed because of your experiences training together. What’s that dynamic like at the range?

AIMEE: Have you ever tried to teach your spouse something? HA! We shoot together all the time and as a couple, manage it better than most.

ERNEST: In all the years we have been going to the range, we can count on one hand the number of times we silently packed up and left the range. Learning when and how to instruct as well as how to be a student while separating the relationship is something we have figured out.

AIMEE: It’s tough to teach and be corrected all the time. However, separating the emotion from the task often helps. And sometimes, he just needs to be reminded, “positive reinforcement helps too,” or “hey, can we just shoot today?”

ERNEST (laughing): Sometimes, I just need to keep my mouth shut.

What were some of the main motivations or “aha! moments” that led to you beginning to consider developing LTT Discover?

ERNEST: We began to develop Discover as we found a missing gap in education and information available for people who are not tactical, LE or related to the LE/MIL community. Being business owners, we are often asked for direction, information and/or training. As we started to get bigger, more people were asking for assistance. We were looking for places to send them.

AIMEE: Guilty by association, the assumption was that early on, I was just as proficient and experienced as Ernest was, and the reality is, at that time, I hadn’t even touched a handgun before we got together. The “Carry Journey” component of Discover was created based on many gun owners’ first-time experiences around firearms or in making the decision to own a firearm while also incorporating health and fitness as a more complete mindset.

Being in the tactical industry, it’s often assumed or impressed upon others that if you are going to own a firearm, you have to do things a certain way and if you don’t, then you shouldn’t even own a firearm. It’s very intimidating for millions of people and many of the gun owners today.

Who is LTT Discover for?

ERNEST: LTT Discover is for everyone—those thinking about firearms ownership to those who own firearms and who carry every day.

LTT Discover screeshot.

When it comes to the 2A space and industry, how important is community and community building to you, and why?

Aimee: Community and Community building is huge, it’s very important to us. We believe a community provides real and raw emotion, tied to being caring and helpful to individuals in a positive way.

A strong community provides a safe place where people can seek information and ask questions without the fear of being belittled or made fun of because they don’t understand and/or are new and don’t know things that some people consider common knowledge.

Ernest: Being a part of a community makes people feel comfortable to ask a question, agree OR disagree, and be guided by trusted and real individuals from a real raw perspective, position or experience background.

What has the initial response to LTT Discover been since its launch?

AIMEE: We are blown away by the positive response from Discover. We have received so many thanks and “ah-ha’s” from men and women alike who feel like the information is proficient, straightforward, and not intimidating. Many enthusiasts who are gun owners have been able to use it as a tool for friends and loved ones to share information and thoughts from real individuals.

As a closing question, what are your personal hopes and dreams for the impact that LTT will have on the industry and the public at large?

AIMEE: As a brand, we hope Langdon Tactical will be a resource not only for products and training (as it is today) but also as an educational resource that provides a welcoming community guiding people to be more confident, self-reliant, and empowered as individuals.

Thank you, Aimee and Ernest, for sitting down to share this exciting new resource. I expect it will help grow the community in a much-needed way. And I’ll definitely be watching to see what comes next.  

Ernest and Aimee Langdon of Langdon Tactical.

To learn more about Langdon Tactical Technology and to explore the LTT Discover platform, visit LangdonTactical.com and LTTDiscover.com.

LTT Discover screeshot.

This article was originally published in the Personal Defense World April/May 2022 issue. Subscription is available in print and digital editions at OutdoorGroupStore.com. Or call 1-800-284-5668, or email subscriptions@athlonmediagroup.com.

Didn’t find what you were looking for?

The post Langdon Tactical Offers Completely Free Training Video Series appeared first on Personal Defense World.

Personal Defense World

Watch 10 minutes of ‘Legend of Zelda: Tears of the Kingdom’ gameplay

https://s.yimg.com/os/creatr-uploaded-images/2023-03/1c0fa3b0-cd78-11ed-bfff-507b777f076f

As promised, Nintendo has showcased 10 minutes of The Legend of Zelda: Tears of Kingdom gameplay — and it’s a useful preview if you’re wondering just how the developers will improve on Breath of the Wild‘s formula. Most notably, producer Eiji Aonuma notes that fusing objects plays an important role in the game. You can build stronger weapons, and even craft vehicles like powered boats and hovercraft. Enemies can use fused weapons too, though, so you can’t assume that a favorite combat strategy will work.

The demo video also shows a way to reach the floating islands above Hyrule (by using a recall ability on an elevator stone), and what happens if you fall or jump off. You have full control all the way down, so you can glide to distant areas or plunge quickly toward the ground. Many mechanics appear familiar, so you won’t have to relearn the fundamentals.

And yes, Nintendo plans to cater to Legend of Zelda devotees with special edition hardware. The company is releasing a Tears of the KingdomOLED Switch (shown below) for $360 on April 28th, weeks ahead of the game’s May 12th launch. You won’t get a copy of Tears, unfortunately, but you will get lavish artwork on the Switch itself, the Joy-Con controllers and the dock. If you already have a Switch, you can also buy Tears-edition Pro Controller ($75) or carrying case ($25).

Nintendo Switch OLED 'Tears of the Kingdom' model
Nintendo

This article originally appeared on Engadget at https://www.engadget.com/watch-10-minutes-of-legend-of-zelda-tears-of-the-kingdom-gameplay-145613610.html?src=rssEngadget

You Can Download the Out-of-Print ‘Zelda: Breath of the Wild’ Explorer’s Guide for Free

https://i.kinja-img.com/gawker-media/image/upload/c_fill,f_auto,fl_progressive,g_center,h_675,pg_1,q_80,w_1200/be5dd0207d3870474a99f79ad89bbd6e.jpg

Photo: Red Herring (Shutterstock)

In anticipation of the new The Legend of Zelda: Tears of the Kingdom set to release on May 12, which you can pre-order for $20 less than the regular price, Nintendo has released The Legend of Zelda: Breath of the Wild – Explorer’s Guide free for you to download. Here’s what you need to know.

What is The Legend of Zelda: Breath of the Wild – Explorer’s Guide?

The Legend of Zelda: Breath of the Wild Explorer’s Guide originally came within a bundle package in 2017.  The Legend of Zelda: Breath of the Wild Explorer’s Edition bundle included the game, an explorer’s map, and the guide. The e-guide is a 96-page PDF walkthrough with information on gameplay mechanics and the world of Hyrule that beginners will find helpful and veterans might find interesting.

What is interesting about this free PDF version is that it is missing pages 73-84, which included sections about “Horsing Around,” “Hyrule’s Wild Side,” “Fiercer Foes,” “The Many Faces of Hyrule,” “The Four Tribes,” and “Great Fairy Fountains.” The reason for the omissions are not known, but Polygon has ruled out that it is for spoiler reasons. Perhaps it’s just an error from Nintendo that might be fixed later.

If you did not get the physical guide back when it was basically free with the game, the price has been inflated quite a bit from its $60 bundle cost, if you could still manage to find it new from reputable stores. The physical version sold out some time ago, although you could still find it for reasonable prices at some second-hand markets.

The timing of the release seems to be clear: At this point, most people will probably not be looking to buy the guide to play a six-year-old game. More than likely, the strategy seems to be to get people hyped about the upcoming Zelda game and get people to finish The Legend of Zelda: Breath of the Wild.

Lifehacker

How I Built a Weather App Using Three Python Frameworks

https://blog.finxter.com/wp-content/uploads/2023/03/image-399.png

5/5 – (1 vote)

Python has several web frameworks for creating web applications.

are some of them.

If you want to become a Python web developer, the importance of learning Django and Flask plus other frameworks can never be overemphasized. There is no better way to learn than working on projects using web frameworks.

???? Recommended: Flask vs Django: Comparing the Two Most Popular Python Web Frameworks

In this three-part tutorial series, I will walk you through the process of building a weather app using three Python frameworks: Django, Flask, and Streamlit. We will start with Django, and if you have been following my project tutorials on Django, this will be an easy ride for you.

Then, for the very first time, I will be creating Python projects using Flask. We will learn this in part two. In the final part of this series, we will see how to create this same application using Streamlit, and have it hosted on Streamlit Cloud for others to use.

A Weather Application

A weather application enables users to get real-time weather information on cities they select. Using powerful web frameworks like Django makes building such an app a fairly easy job for Django developers. All we need is a public API to get real-time information.

We will use the OpenWeatherMap API. So, if you have not already done so, head over to the website and register to get an API key. The API key enables us to benefit from the services rendered by OpenWeatherMap. Make sure you keep your API key safe. We are going to follow best practices for using the API key.

Getting Started

Follow these five steps to set up Django on your system.

  1. Create a folder for this project using any name of your choice and cd into it.
mkdir django-project && cd django-project
  1. Create and activate a virtual environment.
python3 -m venv .venv
. .venv/bin/activate
  1. Install the necessary modules and dependencies.
pip install django requests tzdata
  1. Create a requirements.txt file to store the module versions
pip freeze  > requirements.txt
  1. Then, fire up the local server using the command python3 manage.py runserver to check if everything was installed successfully.

Creating Django project and app

Run this command in your terminal to create a Django project:

django-admin startproject weather .

Don’t forget the dot to create the project in the current directory. The mange.py file is used the execute some Django commands. So, let’s use it to create Django app.

python3 manage.py startapp app

Feel free to use any name of your choice. I briefly explained the function of those files inside the project and app folders. Check it or the documentation if you want to learn more:

???? Recommended: How I Created a URL Shortener App with Django

We have to let Django know that a new app is created. We will do this in settings.py file. Open it and scroll down to INSTALLED_APPS, and add the name of the app.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # custom app
    'app',
]

We are not working with models in this project. So, everything is going to be simple. Let’s now implement the search functionality using the API key.

Using the OpenWeatherMap API

In your app_level folder, create a file called secret_key.py. Then, add your API key there like this:

KEY = 'YOUR API KEY' 

Create another file inside the folder and call it weather.py. You will import the API key there.

import requests
from datetime import datetime
from .secret_key import KEY

def getWeather(city):
    url = f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={KEY}&units=metric'
    response = requests.get(url).json()
    current_time = datetime.now()
    formatted_time = current_time.strftime('%A, %B %d %Y, %H:%M:%S %p')
    context = {
        'city': city,
        'description': response['weather'][0]['description'],
        'icon': response['weather'][0]['icon'],
        'temperature': 'Temperature: ' +  str(response['main']['temp']),
        'country_code': response['sys']['country'],
        'wind': 'Wind: ' + str(response['wind']['speed']) + 'km/h',
        'humidity': 'Humidity: ' + str(response['main']['humidity']) + '%',
        'time': formatted_time
    }
    return context

We import the modules we will use, including the API key.

Then we create a function with a city parameter. This function uses the requests module to get weather information of a given city using the API key. We select only the items we need; and wrap them in a dictionary. We are going to import this function to the views.py file.

Can you see how we use the API key without exposing it?

Creating Views

Open the views.py and let us add in some code.

from django.shortcuts import render
from .weather import getWeather

# Create your views here.

def index(request):
     try:
         if request.method == 'POST':
             city = request.POST['city']
             context = getWeather(city)
             return render(request, 'home.html', context)
         else:
             city_weather = {}
             context = {'city_weather': city_weather}
             return render(request, 'home.html', context)
     except:
        return render(request, 'error.html')

It’s a good practice to create a separate file for the weather information and have it imported into views.py file.

This makes your code neat and readable.

The index() function uses the try statement to make sure the code runs without errors. It checks if the request method was POST, if so, it retrieves the city name and passes it to the getWeather() function.

Finally, it renders the result on the home.html web page. But if there was an error. The error.html web page is displayed.

Registering URLs

Let’s create and register the urls.py file. This file registers all URLs created in the app folder.

from django.urls import path
from .views import index, error

urlpatterns = [
    path('', index, name='home'),

]

We also have to register the application URLs. Go to your project-level folder and open the urls.py file.

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('app.urls')),
]

Creating Templates

Last but not least is templates. Create a templates folder, then go to the settings.py file under the TEMPLATES section.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')], # add these
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Next, create three files inside the folder with the names, base.html, home.html, and errors.html.

base.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Weather App</title>
    <!-- getting bootstrap5 from CDN -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    {% block content %}

    {% endblock %}
</body>
</html>

All other HTML files will inherit from this base.html file. We are using Bootstrap to style the web pages. Now the home.html.

<!-- extends is for inheriting from the base.html -->
{% extends "base.html" %}
{% block content %}
<div class="row justify-content-center my-5">
    <div class="col-md-5">
        <div class="mt-4 p-5 bg-success text-white rounded mb-3">
            <h1>Django Weather App</h1>
        </div>
        <form action="." method="POST">
          {% csrf_token %}
          <div class="input-group">
            <input type="text" required class="form-control" name="city" placeholder="Search City...">
            <div class="input-group-append">
              <button class="btn btn-success" type="submit">
                Search
              </button>
            </div>
          </div>
        </form>
        <hr>
        <div class="card">
           <div class="card-body">
                <img src="http://openweathermap.org/img/w/.png" alt="">
            
                <div class="card-text float-end"></div>
                <div class="card-text"><h5>, </h5></div>
                <div class="card-text"><h6></h6></div>
                <div class="card-text"><h6></h6></div>
                <div class="card-text"><h6></h6></div>
                <div class="card-text"><h6></h6></div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

Django syntax makes it easy to dynamically write to web pages. If you check back on weather.py, you will notice the return results wrapped in a dictionary were dynamically written to the web page using the form.

The form with the action=dot signifies the current URL. The csrf_token protects against malicious attacks.

Finally, the error.html file.

<!-- extends is for inheriting from the base.html -->
{% extends "base.html" %}
{% block content %}
<div class="row justify-content-center my-5">
    <div class="col-md-5">
        <h1>Page Not Found</h1>
        <p>Make sure you are connected to the internet or you are entering a valid city name</p>
        <a href="{% url 'home' %}" class="btn btn-secondary">Home</a>
    </div>
</div>
{% endblock %}

The {% url ‘home’ %} is another way to refer to the home.html web page. Remember the ‘home’ in the urls.py file? Let’s now test the project on the local server. Run python3 manage.py runserver to open the local server.

Conclusion

We have successfully come to the end of this tutorial. We have learned how to create a weather app using Django. The full code is available on my GitHub page.

You have undoubtedly learned many things that can help you while working on projects. Watch out for the second part of this series, where I created the same app using the Flask framework.

Be on the Right Side of Change

That Senate bill to “ban” TikTok? Read the terrifying fine print and kiss your civil liberties goodbye

https://www.louderwithcrowder.com/media-library/image.png?id=33370344&width=980

I am feeling quite bamboozled by this whole "ban TikTok" thing. I was fully on board, but I actually hadn’t read the proposed bill. Silly little me thought that when Congress said they wanted to ban TikTok, they just meant they wanted to ban TikTok. But of course, this is another onion of a bill with little Easter eggs hidden throughout. And these are some pretty scary Easter eggs.

There are actually two proposed bills, but the one we’re talking about is called the "RESTRICT Act." It has support from both parties as well as the White House. And it’s basically a Patriot Act for the internet, as Greg Price on Twitter put it. It gives the government the authority to go after anyone they deem a national security threat. Which could mean actual terrorists, sure. Or it could mean the sad white kid in the basement who excels in the art of meme-making. Either way, the government would have access to basically anything they own that connects to the internet.

The penalties for a violation range from 20 years in jail, $1M in fines, and/or seizing your property. All just because we want the Chinese Communists to stop subverting our youth with half-naked dancing girls. I guess that’s too much to ask.

The bill also allows the White House, through the Commerce Department, to ban social media, gaming, and payment apps. Meaning they can ban video games, video game companies, and might even have the power to go after crypto.

The bill also refers to the ability to ban transactions. The term "transaction" is defined as a "current, past, or potential future transaction." Basically, anything Uncle Sam wants it to be.

But wait, there’s more! All the hullabaloo around TikTok is because it poses an imminent threat from China, a foreign adversary. But in this bill, a "foreign individual" can also be an American citizen! Yaaaay!

And for the cherry on top, any details about each usage of the act is exempt from FOIA. Just cuz. So as much as I hate to agree with the Libertarian Party on anything, it seems they got this one right. You can check out their whole Twitter thread for yourself. And let’s hope this bill doesn’t pass.

><><><><><><

Lily is a Zoomer college dropout who somehow landed a writing gig here at LwC.com. In her spare time, she enjoys going for runs, touching grass, and occasionally tweeting tweets for fellow tweeters.

Facebook doesn’t want you reading this post or any others lately. Their algorithm hides our stories and shenanigans as best it can. The best way to stick it to Zuckerface? Bookmark LouderWithCrowder.com and check us out throughout the day! Also, follow us on Instagram and Twitter.

Louder With Crowder

Best disk space analyzer apps for monitoring your Mac’s storage in macOS

https://photos5.appleinsider.com/gallery/53110-106413-hard-drive-illustration-xl.jpg

Modern Mac storage uses chips, but we still think of spinning disks when it comes to drives. [Unsplash/Patrick Lindenberg]



AppleInsider may earn an affiliate commission on purchases made through links on our site.

If you’re feeling the pinch of limited storage capacity on your Mac, these disk space analyzer apps could help you see how it has been consumed, and potentially free some space up too.

There are numerous macOS apps that allow you to peek into the contents of your Mac’s storage devices. Disk space analyzer apps let you inspect the storage devices connected to your Mac, and take a look at what they contain.

Some of these utilities are simple viewers, which display drive contents as pie charts, graphics, or maps. Others allow you to clean and move files off your devices when they’re no longer needed.

There are several disk scanner utilities for macOS that can grant you to gain quick insight into your drives – far too many to cover here. The most popular disk viewers for macOS include:

Some also provide cleanup/removal abilities.

Only two of the above apps don’t yet have native Apple Silicon binary support: Disk Diag and Disk Analyzer Pro. However, note that in many cases Intel apps running in Apple’s Rosetta 2 emulation layer on M1 and M2 Macs have better performance than if they run natively on Intel Macs.

As usual, you can check for native Apple Silicon versions of any app by selecting it in the Finder and pressing Command-I (Get Info) on the keyboard.

Disk Xray

Disk Xray by Naarak Studio is a simple disk space analyzer and cleaner which can also find duplicate files. The streamlined interface consists of a Scanner window with buttons for scanning, duplicates, and cleanup.

To scan, you first click the small folder button at the top of the window to select a folder or an entire disk volume to scan, then click the Play button. Disk Xray is incredibly fast – scanning large volumes in under a second or two.

Once the scan completes, volume or folder contents are displayed at the bottom of the window, broken down by total, general file types, and subfolders.

Displayed data shows the size of each item, and how much of the total volume space it occupies by percentage. For folders, the number of subitems is also displayed.

Clicking one of the small buttons on the left allows you to delete, open, inspect, and get info on each item. Clicking Delete provides a warning, and if you confirm it, the item or items are deleted from the volume.

The only downside to Disk Xray is that you must rescan for each of the three options: scanning, duplicates, and cleanup. But this is a minor annoyance and the app’s speed more than makes up for the inconvenience.

Disk Xray costs $15, with a 14-day free trial available to try it out.

DaisyDisk

DaisyDisk by Software Ambience Corp is one of the oldest and best disk space analyzers for macOS.

On startup, a list of attached volumes is displayed in a single window. Clicking “Scan” starts scanning a volume, and when the scan is done, a detailed graph showing disk space usage is displayed.

On the right is a list of folders on the volume, and across the top, the current folder’s path on disk. Clicking an item on the right dives into that folder, updating the graph with fluid animation.

You can select any item on the right and drag it to the Collector at the bottom, removing it from the list.

Once you’ve collected all items you wish to remove, clicking the Delete button starts a countdown – giving you time to cancel if you wish. If you don’t cancel, the collected items are deleted from the volume.

This tool is inexpensive and a joy to use – a must-have for your desktop.

DaisyDisk costs $10, but is available with a free trial.

GrandPerspective

GrandPerspective from Eriban Software is a unique and simple volume treemap generator.

The generator shows every file on a volume in a single window containing blocks representing each file or folder. File sizes are indicated by the size of each block in the diagram – with larger blocks indicating larger items.

Using the toolbar along the top, or by right-clicking, you can zoom in and out, delete, open, Quick Look, and reveal items’ locations in the Finder. You can also copy an item’s full path on the disk.

There’s also a Get Info window that allows you to show .pkg contents in the map. The same window lets you change its colors, though some of the pallets are a bit garish.

OmniDiskSweeper

OmniDiskSweeperfrom The OMNI Group is almost as old as the Mac itself and is a disk space analyzer that displays a volume’s items in descending size order for easy removal of large files and folders.

On launch, OmniDiskSweeper displays a simple list of attached volumes, and disk space info for each. Selecting a volume and clicking “Sweep Selected Drive” displays items on that volume in a NeXT-style file browser window.

You can select and view subfolders, including contents of macOS app and .pkg bundles and their contents. You can delete any part of any folder or bundle on the disk by selecting items, and clicking the Trash button.

OmniDiskSweeper may seem a bit simplistic, but keep in mind it’s free, and it was created back when the Mac and its OS and filesystem were much smaller and simpler.

OMNI Group has probably kept it around for historical reasons. There are also older versions available for all versions of macOS back to 10.4 Tiger.

OmniDiskSweeper is free to download, though it’s not the only software the developer produces.

They also make a mean Gantt chart project management app called OMNIPlan ($199, $399 Pro, $20/mo subscription, 14-day free trial).

Disk Drill

Disk Drill by CleverFiles for macOS, iOS, and Android is a disk space analyzer that allows you to scan devices and volumes, and view and remove files and folders. You can also search for deleted files and folders, attempt recovery of lost partitions, and use a host of other features.

Due to lack of disclosure by Apple, Disk Drill can’t run all features on APFS volumes, but it supports macOS Extended (HFS), and Windows FAT32 and NTFS volume formats.

With Disk Drill you can scan both devices and volumes, including RAID devices. There are also S.M.A.R.T monitoring tools, data protection, bit-level backups, trash recovery, a cleaner, duplicate finder, data shredder, free space eraser, and macOS boot drive creator.

The UI is simple enough – with a window displaying each connected device and all its partitions. You can run most operations at both the device and volume level, and there are quick and deep scan levels which trade-off scan speed for completeness.

For a limited time, if you buy the Mac version of Disk Drill, you get the Windows version free.

Disk Diag

Disk Diag from Rocky Sand Studios is a disk space analyzer and cleaner app with features for finding large files, scanning and removing unused System, User, Developer, duplicate files, and unused applications.

There’s a simple OneClick mode and more advanced modes that allow you to view and remove individual files, folders, and apps.

There’s also a feature to scan for unused .dmg disk image files and an overall summary dashboard view. The dashboard view also displays current memory and CPU usage.

Disk Diag also adds a macOS menubar option for quick access, which you can disable.

Disk Space Analyzer and Funter

Disk Space Analyzer from Nektony is a full-featured and aptly named disk space analyzer that also uses sunburst graphs similar to DaisyDisk to display disk storage and contents.

Features include scanning, display, large and unused file search and removal, and copying/moving features.

Nektony also offers a simple macOS menubar product called Funter (free), which allows you to view and clean up both your drives and your Mac’s memory.

Disk Space Analyzer costs $5 per month or $10 per year, and is also offered with a free trial.

Disk Analyzer Pro

Disk Analyzer Pro from Systweak Software is a full-featured disk space analyzer and scanner with a dashboard interface. A simple pie chart with a legend shows disk usage and occupancy by file type/size.

It allows you to search a volume for files and folders by size and type, and to move, delete, and compress files with the single click of a toolbar button.

You can also view all files of a given type instantly in a new window simply by double-clicking on its category in the pie chart legend – a very cool feature.

Additional features include scanning/viewing by subfolders, and the ability to view both the top 100 files by size and date.

Disk Analyzer Pro costs $10 from the Mac App Store.

There’s also a Windows version available.

Built-in

An easy way to view disk usage in macOS is to select “About this Mac” from the Apple menu in the Finder. This opens a device info window for the Mac.

If you then click the More Info” button, you’ll be taken to the System Settings->General->About pane, which has a “Storage” section at the bottom.

Clicking the “Storage Settings” button takes you to an overview pane that shows disk usage for both the internal drive and each category of files stored on your Mac.

If you click the “All Volumes” button, a list of all attached disk volumes, their capacities, and usage graphs are displayed.

Using any of these apps will help you monitor your storage devices, better understand what’s on them, and make it easier to increase free space by removing unwanted and unused files and apps from your drives.

However, depending on your preferences, you may want to try out a third-party disk space analyzer that can provide more granular data for you to use.

AppleInsider News

An elegant way to filter and sort queries in Laravel

https://repository-images.githubusercontent.com/603931433/db3698eb-9e1d-4bfd-a369-4050628b5cc1

Social Card of Laravel Purity

Elegant way to filter and sort queries in Laravel

Tests License Latest Unstable Version PHP Version Require StyleCI

Note if you are front-end developer and what to make queries in an API that uses this package head to queries section

Laravel Purity is an elegant and efficient filtering and sorting package for Laravel, designed to simplify complex data filtering and sorting logic for eloquent queries. By simply adding filter() to your Eloquent query, you can add the ability for frontend users to apply filters based on url query string parameters like a breeze.

Features :

  • Various filter methods
  • Simple installation and usage
  • Filter by relation columns
  • Custom filters
  • Multi-column sort

Laravel Purity is not only developer-friendly but also front-end developer-friendly. Frontend developers can effortlessly use filtering and sorting of the APIs by using the popular JavaScript qs package.

The way this package handles filters is inspired by strapi’s filter and sort functionality.

Tutorials

Video

youtube

Articles

Installation

Install the package via composer by this command:

composer require abbasudo/laravel-purity 

Get configs (configs/purity.php) file to customize package’s behavior by this command:

php artisan vendor:publish --tag=purity 

Basic Usage

Filters

Add Filterable trait to your model to get filters functionalities.

use Abbasudo\Purity\Traits\Filterable;

class Post extends Model
{
    use Filterable;
    
    //
}

Now add filter() to your model eloquent query in the controller.

use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        return Post::filter()->get();
    }
}

By default, it gives access to all filters available. here is the list of available filters. if you want to explicitly specify which filters to use in this call head to restrict filters section.

Sort

Add Sortable trait to your model to get sorts functionalities.

use Abbasudo\Purity\Traits\Sortable;

class Post extends Model
{
    use Sortable;
    
    //
}

Now add sort() to your eloquent query in the controller.

use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        return Post::sort()->get();
    }
}

Now sort can be applied as instructed in sort usage.

Advanced Usage

Restrict Filters

The system validates allowed filters in the following order of priority:

  • Filters passed as an array to the filter() function.
Post::filter('$eq', '$in')->get();
// or
Post::filter(EqualFilter::class, InFilter::class)->get();
  • Filters declared in the $filters variable in the model.

Note applied only if no parameters passed to filter() function.

// App\Models\Post

private array $filters = [
  '$eq',
  '$in',
];
    
// or
    
private array $filters = [
  EqualFilter::class,
  InFilter::class,
];
  • Filters specified in the filters configuration in the configs/purity.php file.

Note applied only if above parameters are not set.

// configs/purity.php
'filters' => [
  EqualFilter::class,
  InFilter::class,
],

Custom Filters

Create custom filter class by this command:

php artisan make:filter EqualFilter

this will generate a filter class in Filters directory. by default all classes defined in Filters directory are loaded into the package. you can change scan folder location in purity config file.

// configs/purity.php

'custom_filters_location' => app_path('Filters'),

Silent Exceptions

By default, purity silences it own exceptions (not sql exceptions). to change that behavior change silent index to false in config file.

// configs/purity.php

'silent' => false,

Queries and javascript examples

This section is a guide for front-end developers who want to use an API that uses Laravel Purity.

Available Filters

Queries can accept a filters’ parameter with the following syntax:

GET /api/posts?filters[field][operator]=value

By Default the following operators are available:

Operator Description
$eq Equal
$eqc Equal (case-sensitive)
$ne Not equal
$lt Less than
$lte Less than or equal to
$gt Greater than
$gte Greater than or equal to
$in Included in an array
$notIn Not included in an array
$contains Contains
$notContains Does not contain
$containsc Contains (case-sensitive)
$notContainsc Does not contain (case-sensitive)
$null Is null
$notNull Is not null
$between Is between
$startsWith Starts with
$startsWithc Starts with (case-sensitive)
$endsWith Ends with
$endsWithc Ends with (case-sensitive)
$or Joins the filters in an “or” expression
$and Joins the filters in an “and” expression

Simple Filtering

Tip in javascript use qs directly to generate complex queries instead of creating them manually. Examples in this documentation showcase how you can use qs.

Find users having ‘John’ as first name

GET /api/users?filters[name][$eq]=John

  const qs = require('qs');
const query = qs.stringify({
  filters: {
    username: {
      $eq: 'John',
    },
  },
}, {
  encodeValuesOnly: true, // prettify URL
});

await request(`/api/users?${query}`);

Find multiple restaurants with ids 3, 6, 8

GET /api/restaurants?filters[id][$in][0]=3&filters[id][$in][1]=6&filters[id][$in][2]=8

  const qs = require('qs');
const query = qs.stringify({
  filters: {
    id: {
      $in: [3, 6, 8],
    },
  },
}, {
  encodeValuesOnly: true, // prettify URL
});

await request(`/api/restaurants?${query}`);

Complex Filtering

Complex filtering is combining multiple filters using advanced methods such as combining $and & $or. This allows for more flexibility to request exactly the data needed.

Find books with 2 possible dates and a specific author.

GET /api/books?filters[$or][0][date][$eq]=2020-01-01&filters[$or][1][date][$eq]=2020-01-02&filters[author][name][$eq]=Kai%20doe

const qs = require('qs');
const query = qs.stringify({
  filters: {
    $or: [
      {
        date: {
          $eq: '2020-01-01',
        },
      },
      {
        date: {
          $eq: '2020-01-02',
        },
      },
    ],
    author: {
      name: {
        $eq: 'Kai doe',
      },
    },
  },
}, {
  encodeValuesOnly: true, // prettify URL
});

await request(`/api/books?${query}`);

Deep Filtering

Deep filtering is filtering on a relation’s fields.

Find restaurants owned by a chef who belongs to a 5-star restaurant

GET /api/restaurants?filters[chef][restaurants][stars][$eq]=5

const qs = require('qs');
const query = qs.stringify({
  filters: {
    chef: {
      restaurants: {
        stars: {
          $eq: 5,
        },
      },
    },
  },
}, {
  encodeValuesOnly: true, // prettify URL
});

await request(`/api/restaurants?${query}`);

Apply Sort

Queries can accept a sort parameter that allows sorting on one or multiple fields with the following syntax’s:

GET /api/:pluralApiId?sort=value to sort on 1 field

GET /api/:pluralApiId?sort[0]=value1&sort[1]=value2 to sort on multiple fields (e.g. on 2 fields)

The sorting order can be defined with:

  • :asc for ascending order (default order, can be omitted)
  • :desc for descending order.

Usage Examples

Sort using 2 fields

GET /api/articles?sort[0]=title&sort[1]=slug

const qs = require('qs');
const query = qs.stringify({
  sort: ['title', 'slug'],
}, {
  encodeValuesOnly: true, // prettify URL
});

await request(`/api/articles?${query}`);

Sort using 2 fields and set the order

GET /api/articles?sort[0]=title%3Aasc&sort[1]=slug%3Adesc

const qs = require('qs');
const query = qs.stringify({
  sort: ['title:asc', 'slug:desc'],
}, {
  encodeValuesOnly: true, // prettify URL
});

await request(`/api/articles?${query}`);

License

Laravel Purity is Licensed under The MIT License (MIT). Please see License File for more information.

Laravel News Links

How to Configure Subdomain routes in Laravel for Domain Driven Design

https://twtv3.ams3.digitaloceanspaces.com/subdomain-routes-laravel.jpg

Also Read: Structure Laravel App for DDD 

Also Read: Routes in Laravel for DDD

If you need to access your routes based on subdomains like product.thewebtier.com/products. To achieve this, you need to modify your route definitions in Laravel and configure web server to handle subdomains.

Modify your route definitions

First, update your route definitions to use subdomain-based routing in the app/Domain/Product/routes/web.php or app/Domain/Product/routes/api.php file.

Also Read: Create own PHP Router

For example, in app/Domain/Product/routes/web.php:

<?php
use App\Domain\Product\Controllers\ProductController;
use Illuminate\Support\Facades\Route;
Route::domain('product.thewebtier.com')->group(function () {
    Route::get('/products', [ProductController::class, 'index'])->name('products.index');
    // Add other product routes here
});

Similarly, you can define routes for other domains in their respective route files.

Configure your Web Server

You need to configure your web server (e.g., Apache or Nginx) to handle subdomains and point them to your Laravel application.

Nginx configuration for DDD

Following example code will work for Nginx configuration for setting up subdomain routing for Laravel application in DDD.

server {
    listen 80;
    server_name product.thewebtier.com;
    root /path/to/laravel/public;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }
    location ~ /\.ht {
        deny all;
    }
}

Apache configuration for DDD

For Apache, create or modify the virtual host configuration:

<VirtualHost *:80>
    ServerName product.thewebtier.com
    DocumentRoot /path/to/laravel/public
    <Directory /path/to/laravel/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Make sure to replace /path/to/laravel with the actual path to your Laravel application.

Configure your DNS

Add a DNS record (A or CNAME) for the subdomain (product.thewebtier.com) and point it to your server’s IP address or domain.

Also Read: MySQL backups in Laravel

After completing these steps, you should be able to access your routes using the subdomain-based URL, like product.thewebtier.com/products.

Laravel News Links