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.
In this video, Ben Holmen teaches us how to manage timezones in your Laravel apps. Some of the highlights include:
Here are the code samples used in the video:
Carbon::macro('inApplicationTimezone', function() {
return $this->tz(config('app.timezone_display'));
});
Carbon::macro('inUserTimezone', function() {
return $this->tz(auth()->user()?->timezone ?? config('app.timezone_display'));
});
Give it a watch and learn all about Timezones and how to easily manage them!
The post Learn how to manage timezones in your Laravel Apps 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-timezones
The Can I PHP? Raycast extension by Diana Scharf lets you check if a certain function or method is available in different versions of PHP. You can see which versions are supported and the deprecation status at a glance:
If you hit Enter, you get a helpful details page from the caniphp.com project. The Can I PHP API is like caniuse.com, but for PHP. The alternative to this extension is manually looking up the PHP documentation and finding when something was introduced; for example, here's the uft8_decode documentation:
To get started with this extension, you can search the store for "Can I PHP":
You can also check out the extension's Raycast page in the Raycast store. The source code is also available on GitHub in the Racast extensions repository.
The post "Can I PHP?" Raycast Extension 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/can-i-php-raycast
WordPress block-based themes allow you to build and customize your website visually, removing the need for code-based tailoring. Fully integrated with the Site Editor, block themes give an unprecedented level of visual control over the layout and style of your site.
In this “Build and Beyond” video, Jamie Marsland walks you through everything you need to know about editing, customizing, and designing every element of your WordPress site using blocks in just 250 seconds. You’ll also get a few sneak peeks of some theme-related features coming in WordPress 6.5 (which will be released March 26, 2024!).
Ready to build on WordPress.com? Start a free trial today:
Start free trialRead more https://wordpress.com/blog/2024/03/21/wordpress-block-themes/
Laravel added a new Context
service to define
contextual data to the current request. Context data is included in
all log entries for that request, and queued jobs will also retain
that same data. Using contextual data allows you to easily trace
back code execution for a given request and any distributed flows
in your application:
// In a middleware...
Context::add('hostname', gethostname());
Context::add('trace_id', (string) Str::uuid());
// In a controller...
Log::info('Retrieving commit messages for repository [{repository}].', [
'repository' => $repo,
]);
Http::get('https://github.com/...');
/*
Log entry example:
[2024-01-19 04:20:06] production.INFO: Retrieving commit messages for repository [laravel/framework]. {"repository":"laravel/framework"} {"hostname":"prod-web-1","trace_id":"a158c456-d277-4214-badd-0f4c8e84df79"}
*/
Contextual data also supports concepts like stacks, where you can push data to the same context, effectively appending data:
Event::listen(function (JobQueued $event) {
Context::push('queued_job_history', "Job queued: {$event->job->displayName()}");
});
Context::get('queued_job_history');
// [
// "Job queued: App\Jobs\MyFirstJob",
// "Job queued: App\Jobs\MySecondJob",
// "Job queued: App\Jobs\MyThirdJob",
// ]
If you'd like to learn more about this feature, check out the Pull Request description. Hat tip to Tim MacDonald, who created this feature for the framework!
The post Introducing the Context Facade in 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-context-facade
Laravel Query Enrich is designed to easily create complex database queries in Laravel without having to write complicated SQL code. Here are some examples taken from the readme:
$recentOrders = DB::table('orders')
->where(c('created_at'), '>=', QE::subDate(QE::now(), 7, Unit::DAY))
->get();
$recentOrders = DB::table('orders')
->whereRaw('created_at >= NOW() - INTERVAL ? DAY', 7)
->get();
SELECT *
FROM `orders`
WHERE `created_at` >= NOW() - INTERVAL 7 DAY;
$monthlyPrices = DB::table('prices')
->select(
QE::avg(c('oil'))->as('oil'),
QE::avg(c('gas'))->as('gas'),
'month'
)
->groupBy('month')
->get();
$monthlyPrices = DB::table('prices')
->select(DB::raw('avg(`oil`) as `oil`, avg(`gas`) as `gas`, `month`'))
->groupBy('month')
->get();
select avg(`oil`) as `oil`, avg(`gas`) as `gas`, `month`
from `prices`
group by `month`
$authors = DB::table('authors')->select(
'id',
'first_name',
'last_name',
QE::exists(
Db::table('books')->where('books.author_id', c('authors.id'))
)->as('has_book')
)->orderBy(
'authors.id'
)->get();
$authors = DB::table('authors')
->select(
'id',
'first_name',
'last_name',
DB::raw('exists(select * from `books` where `books`.`author_id` = `authors`.`id`) as `has_book`'))
->orderBy(
'authors.id',
)
->get();
select `id`,
`first_name`,
`last_name`,
exists(select * from `books` where `books`.`author_id` = `authors`.`id`) as `result`
from `authors`
order by `authors`.`id` asc
$authors = Author::select(
'first_name',
'last_name',
QE::concatWS(' ', c('first_name'), c('last_name'))->as('result')
)->get();
$author = Author::select(
'first_name',
'last_name',
DB::raw("concat_ws(' ', `first_name`, `last_name`) as `result`")
)->first();
select `first_name`, `last_name`, concat_ws(' ', `first_name`, `last_name`) as `result`
from `authors`
Check out the documentation for complete details and view the package on Github.
The post Easily create complex database queries with the Query Enrich Package 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/query-enrich
Page 10 of 1311