The essential news about content management systems and mobile technology. Powered by Perfect Publisher and XT Search for Algolia.
The News Site publishes posts to the following channels: Facebook, Instagram, Twitter, Telegram, Web Push, Tumblr, and Blogger.
The Laravel team released v10.44 this week with two Eloquent model attributes to define global scopes and observers, a new select() collection method, and more:
Eliezer Margareten contributed a ScopedBy
attribute to register global scopes on your Eloquent models:
use App\Models\Scopes\AncientScope;
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
#[ScopedBy([AncientScope::class])]
class User extends Model
{
//
}
You can continue to use the booted()
method in a
model to register global scopes:
/**
* The "booted" method of the model.
*/
protected static function booted(): void
{
static::addGlobalScope(new AncientScope);
}
The ScopedBy
attribute accepts a single observer or
an array of observers, and you can also define multiple attributes
for your model:
// Array type
#[ScopedBy([ScopeOne::class, ScopeTwo::class])]
// Repeatable string type
#[ScopedBy(ScopeOne::class)]
#[ScopedBy(ScopeTwo::class)]
Eliezer Margareten contributed an
ObservedBy
attribute to register model observers on your Eloquent models:
use App\Observers\UserObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
#[ObservedBy([UserObserver::class])]
class User extends Authenticatable
{
//
}
The ObservedBy
attribute accepts a single observer
or an array of observers, and you can also define multiple
attributes for your model if that’s your style:
// Array of classes
#[ObservedBy([UserObserver::class, AnotherObserver::class])]
// Repeatable as string
#[ObservedBy(UserObserver::class)]
#[ObservedBy(AnotherObserver::class)]
The ObservedBy
attribute is an additional way to
register observers, which is traditionally done in a service
provider:
public function boot(): void
{
User::observe(UserObserver::class);
}
Craig Morris contributed a new
Collection::select()
method that selects a certain
number of keys from a multi-dimensional array. The
select()
method is similar to an SQL
SELECT
statement:
$users = collect([
['name' => 'Taylor Otwell', 'role' => 'Developer', 'status' => 'active'],
['name' => 'Victoria Faith', 'role' => 'Researcher', 'status' => 'active'],
]);
$users->select(['name', 'role']);
/*
[
['name' => 'Taylor Otwell', 'role' => 'Developer'],
['name' => 'Victoria Faith', 'role' => 'Researcher'],
],
*/
Mark Townsend contributed
toBase64()
and fromBase64()
to Str and
Stringable. These methods wrap base64_encode()
and
base64_decode()
respectively:
// Using Str
$encoded = Str::toBase64('laravel-news.com');
$decoded = Str::fromBase64($encoded);
// Using Stringable
$encoded = str('laravel-news.com')->toBase64();
$decoded = str($encoded)->fromBase64();
Here’s some example output from a tinker
session:
Ryan Chandler contributed a
Arr::take()
method to take a certain number of items
from an array. It will take from the front of the array with
positive numbers and from the end of the array given a negative
number:
$data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
Arr::take($data, 3); // [1, 2, 3]
Arr::take($data, -3); // [7, 8, 9]
Arr::take($data, 0); // []
Arr::take($data, 1); // [1]
Arr::take($data, -1); // [9]
You can see the complete list of new features and updates below and the diff between 10.43.0 and 10.44.0 on GitHub. The following release notes are directly from the changelog:
getPreviousUrlFromSession
method
in UrlGenerator by @milwad-dev in
https://github.com/laravel/framework/pull/49944setAbly()
method for
AblyBroadcaster
by @Rijoanul-Shanto in https://github.com/laravel/framework/pull/49981toBase64()
and
fromBase64()
methods to Stringable and Str classes by
@mtownsend5512 in https://github.com/laravel/framework/pull/49984Throwable
import and handle
if originalExceptionHandler
or
originalDeprecationHandler
property isn't used by
alternative TestCase by @crynobone in
https://github.com/laravel/framework/pull/50021Arr::take()
helper by @ryangjchandler in https://github.com/laravel/framework/pull/50015GeneratorCommand
by @xurshudyan in https://github.com/laravel/framework/pull/50043The post With Laravel 10.44 you can add Model Scopes and Observers using PHP Attributes appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-10-44-0
We've curated a collection of essential plugins for PhpStorm that we think you’ll enjoy. From our favorite theme to Laravel-specific tools to supercharge your PHP development and a free AI-powered autocomplete/chat plugin that feels like magic.
Nord (JetBrains Marketplace) is an arctic, north-bluish, clean, and elegant JetBrains IDE UI and editor color theme. Designed for a fluent and clear workflow based on the Nord color palette.
The Laravel Idea plugin is an Efficient Laravel Development Environment for PhpStorm. This premium plugin (~$4.90 USD/mo) adds amazing productivity features to Laravel applications:
Check out laravel-idea.com to get started!
The author of Laravel Idea also created the following plugin
we’ll cover, .env
files support, which makes working
with .env
values in your PHP code a breeze.
The .env files support (JetBrains Marketplace)
plugin gives you variable auto-completion, which is very useful
when you need to wire up a .env
value to a Laravel
configuration value. It also supports the following features:
EditorConfig makes coding styles consistent for
multiple developers working on the same project across various IDEs
and editors. This bundled plugin should be enabled by default, but
make sure your project has a .editorconfig
file to
take advantage of these features. Laravel projects ship with an
.editorconfig
file, and you can see that through this
bundled plugin, you can easily navigate and configure code style
for each file type and see what styles extend others at a
glance:
Collector (JetBrains Marketplace) adds support for
Laravel collections, including a bunch of useful refactorings for
making collections better. It can also convert normal PHP
statements like foreach
and array_map
into collections.
Codeium is a free AI Code Completion and Chat tool that is comparable to GitHub copilot. It offers autocomplete and is available for a number of editors, including PHPStorm. You can grab this plugin for PHPstorm on the JetBrains marketplace.
The IntelliVue (JetBrains Marketplace) plugin for
IntelliJ provides analysis, actions, and utilities for
Vue Single File Components. This plugin adds additional
functionality on top of the standard Vue plugin. Full
undo-redo support is enabled, so you are assured that your
important code will not get corrupted by unexpected operations.
Actions
and Intentions
are added to
create and navigate from references to implementation. When
creating a new Vue component option, a dialog is
displayed.
I like how I can easily implement the JavaScript needed for variables in the template using the “Create Vue Implementation” action:
That’s a wrap on our essential plugins for PhpStorm users. I hope you've found something useful to make your development with PhpStorm better! We can't share every single extension, so let us know your favorite PhpStorm plugin or theme we didn't share!
The post Essential Plugins for PHPStorm Users appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/essential-plugins-for-phpstorm-users
In this post, I've gathered some of my favorite tools to make working with Git more productive. I'll cover different types of tools, ranging from git aliases, git tools, git workflows, and more.
I use git
from the command line, so aliases are
essential to my workflow to shorten the number of characters I need
to type and automate multi-step workflows into simple-to-use
aliases. I can't possibly cover every awesome alias—I encourage you
not to go overboard with the number of aliases you have—so share
your favorites with us on social media.
Probably THE most popular alias out there is the git
nah
alias, and lucky for you, we shared The Ultimate "git nah" Alias from developer Liam
Hammett.
If you're working on a feature and you start modifying/creating
files, moving things around, and just want to start over, you can
run git nah
, and it's like it never happened (we won't
tell).
The ultimate nah
alias goes above and beyond the
simple git reset --hard
, and does a few more
things:
--hard
resetclean -df
to clean up directories and
filesrebase --abort
if you have a rebase in
progressHere's the alias you can add to your ~/.gitconfig
file:
# Git alias ⬇️
[alias]
nah = "!f(){ git reset --hard; git clean -df; if [ -d ".git/rebase-apply" ] || [ -d ".git/rebase-merge" ]; then git rebase --abort; fi; }; f"
One of my absolute favorite aliases for cleaning up local
branches after merging them is my git forget
alias. It
fetches the remote, lists branches, filters branches with :
gone]
, and deletes the local version.
My workflow is roughly:
main
main
I can configure GitHub to delete a branch automatically after it's merged; however, cleaning up branches locally is a manual process. I don't necessarily run this command immediately after a merge, but it's an excellent way to clean up those branches that are merged.
If you want to try it out, add the following to your
~/.gitconfig
file:
[alias]
forget="!git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D"
forgetlist="!git fetch -p && git branch -vv | awk '/: gone]/{print $1}'"
The forget
alias is destructive, so I have a
read-only alias as well if I want to see which branches will be
deleted first:
git checkout main
git forgetlist
Be aware that this alias won't delete branches that still have a
remote counterpart. The magic is in the -vv
flag of
the git branch
command, which is described as
follows:
-v, -vv, --verbose
When in list mode, show sha1 and commit subject line for each head, along with
relationship to upstream branch (if any). If given twice, print the path of the linked
worktree (if any) and the name of the upstream branch, as well (see also git remote show
<remote>). Note that the current worktree's HEAD will not have its path printed (it will
always be your current directory).
The -vv
flag prints the linked worktree's path and
the upstream branch's name. Here's what it might look like if you
have a local branch that no longer has a
git branch -vv
* demo-branch b71981eb [origin/demo-branch: gone] chore: bump version
development bd951668 [origin/development] example message
...
Note the gone ]
part, which is what the alias uses
to batch branches that no longer have an associated remote
branch.
Similar to git nah
, the git uncommit
alias is helpful if you haven't pushed code to a remote repository
and you want to remove the commit:
[alias]
uncommit = reset --soft HEAD~1
This is just a shortcut for git reset --soft
HEAD~1
, which essentially rewinds the branch by one commit
and keeps the changes from that commit in the staging area.
You can configure a global commit message template that is used
when you run git commit
without the
-m|--message
flag. You can configure this template as
part of a repository or configure it globally.
# Configure a commit.template globally
git config --global commit.template ~/.gitmessage
# Configure a commit.template in a project
git config commit.template .gitmessage
Here's my global template, which I like to use to remind myself of not only the how of a commit, but also the why and the when:
[one line-summary of changes]
Because:
- [relevant context]
- [why you decided to change things]
- [reason you're doing it now]
This commit:
- [does X]
- [does Y]
I've recently switched to managing my SSH keys for GitHub and
other servers through 1Password, which you can use as your SSH agent. Using 1Password as my agent also
means that I can authorize SSH operations via biometric scanning,
and I don't even have to have an SSH key pair in my
~/.ssh
folder. When using 1Password as an SSH agent,
my private key never leaves 1Password!
If I ever need to create a new key, I can generate one within 1Password and copy the public key to my GitHub.com settings or whatever server I need access.
With 1Password, I have a separate SSH key for key signing on GitHub. I recommend reading Telling Git about your signing key and Sign your Git commits with 1Password for more information. Other tools offer SSH agent features, so I'd recommend you do some research if you use something other than 1Password.
The gh
CLI tool isn't anything new or unique to my
setup, but I enjoy using the command line to work with Git, and
when I am ready to create a pull request, I enjoy using the GitHub
CLI to do so without leaving the terminal using gh pr
create
:
I usually select Continue in browser
, which opens
the GitHub pull request UI with all the pull request information
filled out. This lets me check the file diff and submit the pull
request.
The gh
CLI is also useful for many other things
related to managing your code on GitHub; here are a few of my
favorites that I've incorporated into my workflow:
# use the --watch flags to watch them until they finish 🔥
gh pr checks
# Get the status of a pull request for your current branch (if any)
gh pr status
# Really useful when reviewing pull requests
gh pr checkout 123
# List open issues
gh issue list
If you use git
from the command line, you might fix
merge conflicts by hand or you're smart enough to use the built-in
git mergetool
tool (I am not). Sometimes, I jump into
a GUI tool (i.e., PhpStorm) directly to merge conflicts when I run
into a conflict or edit. Another thing you can do is configure a
different GUI merge tool to work through conflicts and view diffs
in a GUI:
[diff]
tool = opendiff
[mergetool]
keepBackup = false
[merge]
tool = opendiff
Note: you don't need keepBackup = false
if you want
to have a backup around during a merge. You'll have to clean these
up or ignore them though if you don't disable backups.
When I run git mergetool
during a conflict, it will
use opendiff
, which opens the FileMerge
program to give me a visual diff tool. I can also run git
difftool
to visualize the diff in
FileMerge.app
.
If you made it this far, I hope you've found a few things to improve your Git workflow! Let us know your favorite Git workflows, tools, tips, and aliases on your favorite social network!
The post Five Ways to Be More Productive with Git appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/five-ways-to-be-more-productive-with-git
Selecting the design of your website is a critical initial step in establishing your online identity. Our “Design Your Own Theme” feature is a game-changer, offering a variety of Block Patterns to create a unique aesthetic. These Block Patterns provide tremendous flexibility, enabling you to mix and match design elements with ease, ensuring a truly custom and cohesive look across your site.
With an intuitive drag-and-drop interface, our design assembler enables quick layout and style changes. You can easily add, remove, or reposition sections of your website, bypassing the need for complex manual editing. Ultimately, it allows you to explore our diverse design concepts in a user-friendly setting.
We’re offering two sessions of this informative webinar—February 13 and February 28—where we will illustrate how to build a custom website using this innovative tool. The webinar is 100% free to attend and will include a live Q&A session to address all your questions.
Register to attendElevate your website’s visibility with our “SEO Foundations” webinar. Delve into essential techniques as well as how our built-in tools can transform your site’s search engine performance. Our Happiness Engineers will guide you through integrating effective SEO strategies so that readers and customers will find you with ease.
Register to attendTransform your approach to content creation with our “AI-Assisted WordPress” webinar. We’ll guide you through using our innovative Jetpack AI Assistant, which has been built help you brainstorm, edit, and generally assist all your writing efforts. Join us and step into a new realm of efficient and creative content production.
Register to attendRead more https://wordpress.com/blog/2024/02/12/february-webinars/
Jack McDade, founder of Statamic, just launched a brand new design course called Radical Design.
It's not a book, and it's not a step-by-step video course either. It's a self-guided, Choose Your Own Adventure™ style hub that dives deep into many different areas of design. Yes, it includes (many) videos, articles, and tutorials, but also downloads, example design files, elements, components, hand-crafted SVGs, and all sorts of other good stuff. I’m going to share all my resources, secrets, and my personal treasure trove of hot links (bookmarks, not sausages), font recommendations, asset libraries, and more.
If you know Jack, you know he has a wild design style that really works. His designs are unique, creative, and super fun. I’m always inspired every time he launches something new.
If you are looking to get into design and are not sure where to start, then this course is for you. You’ll learn:
You can buy the course at Radical Design Course, and you’ll get the course access to the private Radical Design Discord server so you can collaborate, share ideas, and give feedback.
Plus, the course will be regularly updated with new videos and resources.
The post Radical Design - A new course by Jack McDade appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/radical-design-a-new-course-by-jack-mcdade
Page 25 of 1312