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 binafy/laravel-cart package adds the ability to add shopping cart functionality to Laravel applications. It simplifies storing and managing cart items, supports storing multiple item types, and more:
From the package's documentation, here's an example of retrieving a cart for a given user and adding an item to the cart:
$cart = Cart::query()->firstOrCreate(['user_id' => $user->id]);
$cartItem = new CartItem([
'itemable_id' => $itemable->id,
'itemable_type' => $itemable::class,
'quantity' => 1,
]);
$cart->items()->save($cartItem);
// Or create and store
Cart::query()->firstOrCreateWithStoreItems(
item: $product,
quantity: 1,
userId: $user->id
);
This package also allows you to store multiple items in the
cart, and the cart items are polymorphic model associations. You
can access the underlying model associated with the
CartItem
using the itemable()
method:
$cartItem->itemable()->first();
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
Related: GetCandy E-commerce Package for Laravel
The post A Lightweight Cart Package for Laravel 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-cart-package
We just released Headless UI v2.1 for React, which dramatically simplifies our transition APIs and adds support for rendering multiple dialogs as siblings.
We just released Headless UI v2.1 for React, which dramatically simplifies our transition APIs and adds support for rendering multiple dialogs as siblings.
We’ve made transitions way easier in v2.1 by adding a new
transition
prop to all of the built-in components you
might want to transition, and adding data attributes for each
transition stage so you can add transition styles by just throwing
some classes on the target element:
import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'
function Example() {
return (
<Menu>
<MenuButton>My account</MenuButton>
<MenuItems
transition
className={`
transition ease-out
data-[closed]:scale-95 data-[closed]:opacity-0
data-[enter]:duration-200 data-[leave]:duration-300
`}
>
{/* Menu items… */}
</MenuItems>
</Menu>
)
}
There are four data attributes you can use to target the different stages of your transitions:
data-closed
: The styles the element should
transition from when entering and to when leaving.data-enter
: Styles to apply while the element is
entering, like a duration or easing curve.data-leave
: Styles to apply while the element is
leaving, like a duration or easing curve.data-transition
: Styles to apply while the element
is entering or leaving, useful for sharing values between both
stages.You can even stack these attributes to use different
closed
styles for entering and leaving. For example
this dialog slides in from the left, but slides out to the
right:
import { Dialog Transition } from '@headlessui/react'
import { useState } from 'react'
function Example() {
let [isOpen, setIsOpen] = useState(false)
return (
<>
<button onClick={() => setIsOpen(true)}>Open dialog</button>
<Dialog
open={isOpen}
onClose={() => setIsOpen(false)}
transition
className={`
transition ease-out duration-300
data-[closed]:opacity-0
data-[closed]:data-[enter]:-translate-x-8
data-[closed]:data-[leave]:translate-x-8
`}
>
{/* Dialog content… */}
</Dialog>
</>
)
}
And for transitioning regular HTML elements or other components,
you can still use the <Transition>
component but
with the new data attribute APIs:
import { Transition } from '@headlessui/react'
import { useState } from 'react'
function Example() {
const [isShowing, setIsShowing] = useState(false)
return (
<>
<button onClick={() => setIsShowing((isShowing) => !isShowing)}>Toggle</button>
<Transition show={isShowing}>
<div className="transition duration-300 data-[closed]:opacity-0">
I will fade in and out
</div>
</Transition>
</>
)
}
We’ve already updated all of Tailwind UI to use this new transition API and the code is a lot simpler and lighter. Take a look at the Modal Dialog, Dropdown, Slide-over, Flyout Menu, or Select Menu components for more examples.
All of the existing APIs continue to work for backwards compatibility, but this new approach is what we’re going to recommend going forward.
Check out the updated Transition
component documentation to
learn more.
In Headless UI v2.1 you can finally render multiple dialogs at the same time without nesting one inside the other.
This can be really helpful when two unrelated parts of your application need to show a dialog at the same time — for example maybe you already have some sort of confirmation dialog open but another part of your app detects that you’ve lost network connectivity or your session has timed-out and needs to throw up a new dialog on top.
Here’s what something like that might look like with Catalyst, the application UI kit we’ve been working on recently:
We keep track of the order in which each dialog is opened, and whichever one was opened last is the one that will close when you press escape or click outside the dialog.
To start using this stuff today, just install the latest version of Headless UI:
$ npm i @headlessui/react@latest
If you run into any issues, let us know on GitHub!
(The post Headless UI v2.1: Simplified transition API and improved multi-dialog support appeared first on Tailwind CSS Blog.)
Read more https://tailwindcss.com/blog/2024-06-21-headless-ui-v2-1
SQLite seems to be cropping up everywhere! Laravel 11 uses SQLite by default when creating a new project, and Rails' default database is SQLite as well. A host of Database GUIs now support SQLite. Production services like Turso help use SQLite in production, and many prominent community developers are promoting SQLite.
We covered TablePlus on Laravel News in 2017, and it remains a solid GUI option for managing SQLite databases. Other options include integrated database tools in PHPStorm and other JetBrains products, a full-on database IDE by JetBrains called DataGrip, and many others.
SQLite Studio doesn't necessarily compete with the above-mentioned GUI tools; it is a single-file binary, single-command SQLite database explorer. It offers the following features:
My favorite feature is the infinite scroll rows view and the responsive updates as you write SQL queries in the Queries tab:
SQLite Studio also gives you a Birds Eye view of the database on the Overview tab, which summarizes the database file size, SQLite version, total number of tables, rows per table, metadata, and more:
The technology behind SQLite Studio looks fantastic—it uses Rust for the backend and TypeScript, React, Tailwind CSS, and Vite for the UI. If you want to see a live version of SQLite Studio in action, check out SQLite Studio's sample.db. This CLI is open-source on GitHub at frectonz/sqlite-studio.
Related: DevDB - Access your database right inside VS Code! - Laravel News
The post SQLite Studio is a SQLite Database Explorer 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/sqlite-studio
This year’s WordCamp Europe was held in Torino, Italy, the capital city of the Piedmont region in northern Italy. Torino is known for its rich automotive history, beautiful architecture, and, of course, incredible food.
From June 13-15, 2024, over 2,500 folks from the WordPress community, including many of us from the WordPress.com team, came together to learn, connect, and give back to the WordPress project that powers over 43% of the entire internet.
I joined the WordPress.com team back in January of this year, so WordCamp Europe 2024 was my first WordCamp experience. In today’s post, I thought it might be interesting to hear about the conference from a first-timer, especially if you’re considering attending a WordCamp or WordPress meetup in the future.
Here are my top five takeaways from my very first WordCamp:
If your typical workday looks similar to mine––sitting at a desk at your house all day by yourself––going to a conference as large as WordCamp Europe may be a wee bit out of your comfort zone. It certainly was out of mine.
That said, I’ve recently found myself craving in-person connection after the pandemic and working almost exclusively from home for over eight years. Not only did attending this conference just get me out of my normal routine, it allowed me to connect with folks who love the tool I’ve used personally and professionally for over a decade: WordPress.
I staffed the WordPress.com booth, so I had a ton of opportunities to chat with other business owners, developers, creators, and makers over the course of the conference. I actually talked with a few fellow self-taught women developers like me, and I walked away feeling inspired, motivated, and just really thankful to be a part of this community.
But the best conversations happened in places I wouldn’t have expected: over spritzes, grabbing a cafe at the venue, or just walking around the city.
Embracing connection was a big focus of Matt’s final keynote speech during the event, and I couldn’t agree more. Events like WordCamps allow for swapping ideas, collaborating and troubleshooting, and experiencing a sense of community that you just don’t get while sitting behind a computer.
That said, if large-scale conferences like a flagship WordCamp just aren’t for you, try checking out a local WordPress meetup to connect with other like-minded folks in your community.
One of the most moving parts of WordCamp Europe was at the very end when all of the volunteers and organizers were called to the stage; it’s truly amazing just how many people need to be involved to make an event like WordCamp actually happen.
Everything was smooth and well-organized, and the volunteers and organizers could not have been more helpful. Their enthusiasm about the event, WordPress, and community in general throughout the conference was infectious.
WordCamps and local WordPress meetups are always looking for volunteers; donating your time and expertise for events and meetups like this are a great way to give back to the WordPress project and community.
And if you’re an organizer of your local WordPress meetup, check out this post for information on how you can get a free WordPress.com website for your local meetup.
I’ve never contributed to WordPress core, but it was one of my goals for this year. That’s why I was so excited to participate in Contributor Day at WordCamp Europe.
If you’re unfamiliar with Contributor Day, it’s an event that usually kicks off a WordCamp. Teams focus on contributing to the WordPress open source project, with groups focused on code, support, translations, sustainability, inclusion, and more.
After listening to all of the team presentations, I decided to join the Accessibility team. Accessibility is something that has always interested me, but it’s also something I don’t have a ton of experience with.
That said, my inexperience wasn’t just accepted, it was actively welcomed.
Once I got to the Accessibility team table, I was immediately greeted and welcomed. Then I paired with a fellow contributor, Marco Acato from Acato Digital Agency, to test the accessibility of a new theme for the WordPress theme repository.
I learned so much, asked a ton of questions, and felt surprisingly accomplished after just a few hours of testing this theme. We were actually able to publish feedback for the theme developer at the end of the day as well.
Contributor Day gave me an even deeper appreciation for the entire community that supports the WordPress project every single day. So much work and effort goes into maintaining and improving this tool that millions of websites across the world rely on to run their businesses, amplify their messages, and stay in touch with others. I felt so grateful to have been a part of it during Contributor Day and would encourage any other first-timers to attend a Contributor Day in the future as well.
Luckily, WordPress core is always looking for volunteers and contributors; check out this guide or the new Contributor Mentorship Program if you’re interested in becoming a contributor yourself.
Between attending Contributor Day and sessions, to checking out sponsor booths and attending side events, I didn’t think we’d have a ton of time to actually see the city or Torino.
I actually had plenty of time to explore with my coworkers, eat pizza every single day, and scope out the best gelato spots outside of conference hours.
The WordCamp Europe team did a great job preparing attendees to make the most of our time in the city as well; their travel guides helped me feel confident navigating the city and finding some of the foods that come from this area in Italy.
As a first-timer in Torino, I really appreciated the extra work that the WordCamp team did to ensure everyone had a chance to explore and experience the city.
I would be remiss to not mention the food that we ate during our time in our host city! While we like to say that “Code is poetry” around here, so is pizza.
One of my very favorite memories from the event was the branding. The design team for WordCamp Europe 2024 added subtle nods to our host country throughout the venue, which was incredibly clever and well-done.
And while pizza is indeed poetry, it’s even better when shared amongst coworkers, friends, and people who get excited about the same things that excite you.
I loved my time at WordCamp Europe, and I’m already looking forward to the next time I can connect face-to-face with the WordPress community.
Were you at WordCamp Europe this year? Leave a comment with your favorite memory from the event below.
Read more https://wordpress.com/blog/2024/06/20/wceu-2024/
Nuno Maduro recently shared the ->only()
method you
can attach to tests with PestPHP. I love targeted ways to run and
rerun tests efficiently, and this helper sparked an idea to collect
the various ways to filter, skip, and target tests in PHP. This
post is by no means exhaustive, but I hope to cover the most
important techniques. I'll cover both PHPUnit and Pest, where each
tool applies.
Before we get started, here's a look at the only()
method Nuno shared that you can attach to individual tests:
it('returns a successful response', function () {
$response = $this->get('/');
$response->assertStatus(200);
})->only();
// If you use ->only() with multiple tests it will
// run all of those selected tests.
it('another test', function () {
// ...
})->only();
Using only()
acts as a switch that will target
individual tests while you focus on writing code and running tests
for that feature. Besides the only()
helper, both
PHPUnit and Pest provide plenty of ways to isolate, skip, and
iterate on a selected set of tests.
Let's take a look!
Regardless of a project's size, I prefer to run small groups of tests in isolation while I work on a feature. Learning how to select and filter tests in PHP is an invaluable skill for developers to practice with.
Pest has many options for filtering tests—including the
aforementioned ->only()
method—using a combination
of code or command line flags.
Here are some of the flags Pest offers to filter tests:
pest --dirty
pest --bail # stop execution on first non-passing test
pest --filter 'returns a successful response'
pest --retry # reorders higher priority to failed tests
pest --group|--exclude-group # Like PHPUnit, filter by test groups.
pest --todo # List tests marked as `->todo()`
There are other flags and options for test selection in the Pest CLI Reference.
PHPUnit also has a variety of ways to filter tests that you can use on the command line:
# filter which tests to run
phpunit --filter test_the_application_returns_a_successful_response
# Group flags
phpunit --list-groups # list available groups
phpunit --group api
phpunit --exclude-group live
PHPUnit has a variety of other selection options that you can
see by running phpunit --help
or visiting the PHP CLI selection documentation. Laravel's Tim
MacDonald wrote Tips to Speed up Your Phpunit Tests on Laravel News,
which is a resource I recommend to build your test management
skills.
Pest offers selections similar to PHPUnit and builds some excellent DX helpers on top of PHPUnit that I find invaluable.
Skipping tests is useful when validating your test suite, but know that some tests are either outright broken or a work in progress. A theme I am seeing is that PHPUnit offers the ability to skip tests, and Pest builds on top of that with productive tools that empower you to Brainstorm Tests With PEST Todos and other test-skipping goodies.
When I am writing a new feature, I get tons of ideas as I work on the initial features. Ideas come faster than I can write, so I jump to the test file and start creating a to-do checklist right in the code!
it('returns a successful response', function () {
$response = $this->get('/');
$response->assertStatus(200);
});
it('requires a valid email')->todo();
it('detects Gmail addresses with a "+" as a non-unique email.')->todo();
it('requires a strong password')->todo();
I can then run pest --todo
and know exactly where
to find new features or tests that I didn't quite finish and want
to revisit.
PHPUnit has CLI flags you can use to select/skip tests, such as
the --exclude-filter
or --exclude-group,
which are broader. When you want to skip a specific test, you can
use the provided markTestIncomplete()
method in the
test:
public function test_the_application_returns_a_successful_response(): void
{
$this->markTestIncomplete('it requires a valid email');
$response = $this->get('/');
$response->assertStatus(200);
}
If you run the test suite, you will get a note that you have one
or more incomplete tests. You can list all of the incomplete tests
in more detail using the --display-incomplete
flag:
I interpret incomplete tests to be the closest equivalent to
Pest's todo()
method. While you can achieve similar
using markTestAsSkipped()
, I would reserve that for
skipping tests that shouldn't run on a target platform or given
scenario.
If your codebase supports multiple versions of PHP, sometimes it makes sense to skip specific tests on a given set of PHP versions, Operating systems, or extensions. Both Pest and PHPUnit offer flexible support for these needs.
PHPUnit has a RequiresPhp
attribute you can use to
target PHP versions in tests, as well as various operating system
attributes:
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use PHPUnit\Framework\Attributes\RequiresPhp;
#[RequiresPhp('<=8.0.0')]
#[RequiresOperatingSystemFamily('Windows')]
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
Note: Historically, PHPUnit used the @requires annotation (which is now deprecated) to target multiple types of common preconditions like PHP version, OS, functions, etc.
When you run the above test, it is skipped for systems running a
PHP version >8.0.0
or OS other than the
Windows
family. Running the test suite with
--display-skipped
gives you details on any skipped
tests based on these attributes:
As part of Pest's Skipping Tests docs, you can use the following methods to skip certain PHP versions, OS versions, etc.
it('has home', function () {
//
})->skipOnPhp('>=8.0.0');
it('has home', function () {
//
})->skipOnWindows(); // or skipOnMac() or skipOnLinux() ...
it('has home', function() {
//
})->onlyOnWindows(); // or onlyOnMac() or onlyOnLinux() ...
The last thing to mention is that IDEs offer ways to quickly run individual tests, groups of tests, all tests in one file, etc., with quick command shortcuts. The Better PHPUnit VS Code Extension supports both PHPUnit and Pest, and provides the following features:
PHPStorm offers a ton of useful ways to run (and rerun) tests with shortcuts and UI icons, making it super easy to run a test from the test file without jumping to the command line: See the PhpStorm documentation for details on setting up testing shortcuts and tools for both PHPUnit and Pest.
An honorable mention is the sublime-phpunit plugin that gives you the ability to run Run individual unit tests and files directly from Sublime.
What other IDE and text editor tools do you use to automate running tests? Let us know!
The post Running a Single Test, Skipping Tests, and Other Tips and Tricks 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/run-single-tests-skip-tests-phpunit-and-pest