The iTunes feature that let you stream your personal media to other devices like an Apple TV is still in macOS Catalina, but the procedure is a bit different. Here’s what you need to know to set it up, turn it on, and why it’s worth doing.
via AppleInsider
How to turn on Home Sharing in the Music and TV apps in macOS Catalina
Comic for October 06, 2019
Transcript
Man: I hear what you’re saying, and I disagree.
Dilbert: Because…?
Man: Because what?
Dilbert: Do you have any reasons for your disagreement?
Man: No, I’m a lifestyle disagreer. I disagree with everyone all the time. The reasons are irrelevant.
Dilbert: You sound smart.
Man: No. I’m not smart.
Dilbert: And you’re attractive too.
Man: No. I’m ugl…okay, I see what you’re doing.
Star Trek: Picard (Trailer 2)
CBS All Access drops another look at the upcoming Jean-Luc Picard series, which kicks off with the best Starfleet Captain ever coming out of retirement to come to the aid of a mysterious young woman. And the Captain now has two Number Ones – his cat, and Lieutenant Riker. Premieres 1/23/20.
It’s just one big ST:NG reunion in latest trailer for Star Trek: Picard
Star Trek fans have been eagerly awaiting the debut of the new series, Star Trek: Picard, slated to debut in January 2020. It was first announced at the Las Vegas Star Trek Convention in August 2018, and a nice long trailer just debuted at New York Comic-Con. It’s practically a Star Trek: The Next Generation reunion, featuring plenty of familiar faces alongside the new cast.
Rumors began swirling about a Picard-centric spin-off series shortly after Star Trek: Discovery showrunner Alex Kurtzmann signed a five-year development deal with CBS to further expand the franchise for its streaming service. One potential snag was whether Patrick Stewart, who created the character, would be willing to reprise his role. Kurtzman envisioned a more contemplative tone, describing the series as “a more psychological show, a character study about this man in his emeritus years.” The concept was sufficiently unique that Stewart signed on.
“I truly felt my time with Star Trek had run its course,” Stewart said at the 2018 convention. But he professed himself “humbled” by the stories from fans about how much the character of Picard and ST:NG had brought comfort to them during difficult times in their lives. “I feel I’m ready to return to him for the same reason—to research and experience what comforting and reforming light he might shine on these often very dark times.” There are ten episodes in the first season, with plans for two additional seasons if the series succeeds.
The first trailer debuted at San Diego Comic Con in July. Picard has retired to the family vineyard, filled with regret because Data sacrificed his life to save him in Star Trek: Nemesis. (The series is set about 20 years after those events.) His bucolic existence is interrupted by the arrival of a mysterious woman named Dahj (Isa Briones), who pleads, “Everything inside of me says that I’m safe with you.” It’s unclear who she is, but she has shapeshifting powers and is quite the athlete. Clearly Picard has his suspicions, telling an admiral at what appears to be a Starfleet outpost, “If she is who I think she is, she is in serious danger.”
We caught glimpses of of Seven of Nine (Jeri Ryan) and Data (Brent Spiner). And the SDCC unveiling included confirmation that at least two other regulars from ST:NG would at least make an appearance on Picard: Hugh (Jonathan Del Arco) and William Riker (Jonathan Frakes). We do indeed catch sight of Riker in this latest trailer, along with Deanna Troi (Marina Sirtis). The new cast members include Christobal (Santiago Cabrera), a skilled thief who becomes the pilot of Picard’s ship; Raffi (Michelle Hurd), a former intelligence officer and recovering addict; Dr. Agnes Jurati (Alison Pill); and two Romulan refugees, Elnor (Evan Evagora) and Narek (Harry Treadaway).
The new trailer opens with a dream sequence, as Picard encounters Data in the vineyard working on a strangely haunting painting of a woman. He offers to let Picard complete the painting but Picard responds he doesn’t know how. “That is not true, sir,” Dream Data replies, handing him the paintbrush. As images of past tragedy flash by, Picard wakes up next to his trusty dog, Number One. “I came here to find safety,” he says in a voiceover. “But one is never safe from the past.”
When the mysterious Dahj shows up, he travels to Federation headquarters to convince them to help her. But he’s been gone a long time, and his entreaties are rebuffed. Never one to admit defeat, Picard amasses his own crew, both old and new faces, for a top-secret unauthorized rescue mission. “The past is written,” he intones. “But we are left to write the future,”
Star Trek: Picard premieres January 23, 2010, on CBS All Access. Feel free to toast the occasion with a nice glass of Star Trek Wine.
Listing image by YouTube/CBS All Access
via Ars Technica
It’s just one big ST:NG reunion in latest trailer for Star Trek: Picard
7 Free Bootable Antivirus Disks to Clean Malware From Your PC
Your antivirus or antimalware suite keeps your system clean. At least, it does most of the time. Security programs are better than ever, but some malware still squeezes through the gaps. There is also the other common issue: the human touch. Where there is a human, there is a chance for malware to slip through.
When that happens, you can reach for a bootable antivirus disk. A bootable antivirus disk is a malware removal environment that works like a Linux Live CD or USB. Here are seven free bootable antivirus disks you should check out.
1. Kaspersky Rescue Disk
The Kaspersky Rescue Disk is one of the best bootable antivirus disks, allowing you to scan an infected machine with ease. The Kaspersky Rescue Disk scanner has a reasonable range of antivirus scanning options, including individual folder scanning, startup objects, system drive, and fileless objects. You can also scan your system boot sectors, which is a nice option to find stubbornly hidden malware.
That said, the Kaspersky Rescue Disk does come with a smattering of additional tools, such as Firefox, a file manager, and more.
Another handy Kaspersky Rescue Disk feature is the graphic or text-based interface. For most users, the GUI is the best option, but the text-only mode is available for low power machines or otherwise.
Kaspersky consistently achieves high scores in antivirus testing, and the Kaspersky Rescue Disk brings that to you in a bootable format. Kaspersky also features in our list of the best antivirus suites for Windows 10.
Download: Kaspersky Rescue Disk (Free)
2. Bitdefender Rescue CD
Bitdefender Rescue CD is of the same ilk as Kaspersky’s offering. It is a large download, has a simple to use UI, and comes with several antivirus scan options to help you figure out what’s wrong with your system.
The scanning interface is easy to navigate, allowing you to exclude certain file types, scan archive files (such as a .ZIP or .7z), scan files below a particular size, or just drag and drop individual files into the scanner. For the most part, however, the standard scan is fine as you want to make sure your system is free of malware.
Also included in the Bitdefender Rescue CD is Firefox, a file browser, disk recovery tool, and a few other utilities.
The major downside to Bitdefender Rescue CD is that it is no longer updated; therefore, the virus signatures are outdated. Still, it is a decent rescue disk.
Download: Bitdefender Rescue CD (Free)
3. Avira Rescue System
Avira Rescue System is an Ubuntu-based bootable antivirus rescue disc. The Avira Rescue Disc is one of the best bootable antivirus environments for beginners, as it includes a handy guide to walk you through scanning your drives. Moreover, Avira offers very little in the way of scan customization. Again, this might suit a beginner, as there is less chance of turning part of a scan off and missing a malicious file.
The Avira Rescue System environment is easy to navigate, with a streamlined interface of labeled boxes. Like the other options, the Avira Rescue System includes a web browser and a disk partitioning tool amongst others.
As Avira is an Ubuntu-based rescue disk, it also works well with Linux-based systems.
Download: Avira Rescue System (Free)
4. Trend Micro Rescue Disk
From three of the largest bootable antivirus rescue disks to the smallest. The Trend Micro Rescue Disk may well be the smallest bootable antivirus disk on this list, but it packs a handy punch that will help you regain control of your system.
Given its size (around 70MB at the time of writing), you can forgive that the Trend Micro Rescue Disk has no graphical user interface. Instead, you use the rescue disk exclusively through plain text menus. It sounds a little daunting. But in practice, the text menus are simple to navigate, and you will find your way through.
Download: Trend Micro Rescue Disk for Windows (Free)
5. Dr.Web Live Disk
Despite the slightly suspect name (Dr.Web sounds like a phony internet firm, to me at least), Dr.Web Live Disk offers a wide range of antivirus scanning options in its bootable antivirus environment. In comparison with the alternatives, Dr.Web’s range of scanning options is extensive.
For instance, you can configure the types and sizes of files for inclusion and exclusion. You can set individual actions for specific types of malware, such as a bootkit, dialer, adware, and so on. You can also limit the amount of time the virus scan spends on individual files, handy if you have multiple large media file types.
Dr.Web Live Disk has another string in its bow, too: you can use it to scan Linux systems.
Download: Dr.Web Live Disk (Free)
6. AVG Rescue
AVG is one of the most recognizable names in security. The AVG Rescue disk has a very basic, text-only interface, but it does allow for customizable scanning.
For instance, you can mount a specific Windows volume and scan only that, or scan specific files within that volume. Alternatively, you can scan Windows Startup objects or even just the Windows Registry to seek out specific malware types. (Should you clean the Windows Registry, anyway?) In addition, AVG Rescue comes with a few diagnostic and analytical tools to help you fix drive specific issues, rather than just straight-up malware.
The very basic text interface won’t be everyone’s cup of tea. Having to navigate back and forth through the interface using the arrow keys is infuriating at times. But, given the range of options available and the accuracy of the AVG Rescue disk scanner, you might overlook the arrow keys.
Download: AVG Rescue (Free)
7. ESET SysRescue Live
The final bootable antivirus disk for your consideration is ESET SysRescue Live, an advanced antivirus rescue disk with lots of features.
ESET SysRescue Live comes with extensive antivirus scan control. You can scan archives, email folders, symbolic links, boot sectors, and more, or use the ESET scan profiles. The ESET SysRescue Live disk also packs in a disk analysis tool to check for defects and other failures, plus a memory test tool to check your system RAM for errors.
The rescue environment also comes with the Chromium browser, partition manager GParted, TeamViewer for remote system access, and a smattering of other handy utilities.
Download: ESET SysRescue Live (Free)
What Is the Best Free Bootable Antivirus Disk?
For me, the best free bootable antivirus disk is a toss-up between Kaspersky Rescue Disk and Dr.Web Live Disk.
The Kaspersky Rescue Disk is cumbersome but effective, updating regularly and backed with Kaspersky’s excellence in the field of security. But it doesn’t have the same extensive functionality as the Dr.Web Live Disk. While the latter cannot truly compete with Kaspersky on scanning terms alone, the scanning options available in the Dr.Web Live Disk make it a handy tool.
Regarding the other tools, all are strong and will clean your system. Depending on the severity of the malware, you could download two bootable antivirus disks and run them one after the other to make sure nothing slips through the net.
For more malware removal advice, check out our malware removal guide.
Image Credit: Asiorek/Depositphotos
Read the full article: 7 Free Bootable Antivirus Disks to Clean Malware From Your PC
via MakeUseOf.com
7 Free Bootable Antivirus Disks to Clean Malware From Your PC
Now UI Dashboard Preset for Laravel
Now UI Dashboard Preset for Laravel
The Laravel Frontend Presets GitHub organization has a frontend preset for Now UI, a Bootstrap 4 admin template. Speed up development with this admin dashboard for Laravel 5.5:
After installing Now UI with composer, you can install it in your project with the following preset command:
php artisan preset nowui
The Now UI preset includes stubs for a profile page, a generic page, and a user controller to manage users.
You can learn more about this package, get full installation instructions, and view the source code on GitHub at laravel-frontend-presets/now-ui-dashboard.
Filed in: News
Enjoy this? Get Laravel News delivered straight to your inbox every Sunday.
No Spam, ever. We’ll never share your email address and you can opt out at any time.
Eloquent Basics: Relations Form with Searchable Dropdown [Live-Coding]
Video answering a question from another video comment – a lesson where you will learn some Eloquent, some Laravel 6 UI, some Seeding, some Select2 + jQuery.
via Laravel News Links
Eloquent Basics: Relations Form with Searchable Dropdown [Live-Coding]
Paper Dashboard Laravel – Free Frontend Preset for Laravel
Frontend version: Paper Dashboard v2.1.1. More info at https://www.creative-tim.com/product/paper-dashboard-2/?ref=pdl-readme
Speed up your web development with the Bootstrap 4 Admin Dashboard built for Laravel Framework 5.5 and up.
Note
We recommend installing this preset on a project that you are starting from scratch, otherwise your project’s design might break.
Prerequisites
If you don’t already have an Apache local environment with PHP and MySQL, use one of the following links:
Also, you will need to install Composer: https://getcomposer.org/doc/00-intro.md
And Laravel: https://laravel.com/docs/6.x/installation
Installation
After initializing a fresh instance of Laravel (and making all the necessary configurations), install the preset using one of the provided methods:
Via composer
Cd
to your Laravel app- Install this preset via
composer require laravel-frontend-presets/paper-dashboard
. No need to register the service provider. Laravel 5.5 & up can auto detect the package. - Run
php artisan preset paper
command to install the Argon preset. This will install all the necessary assets and also the custom auth views, it will also add the auth route inroutes/web.php
(NOTE: If you run this command several times, be sure to clean up the duplicate Auth entries in routes/web.php) - In your terminal run
composer dump-autoload
- Run
php artisan migrate --seed
to create basic users table
By using the archive
- In your application’s root create a presets folder
- Download an archive of the repo and unzip it
- Copy and paste paper-dashboard-master folder in presets (created in step 2) and rename it to paper
- Open
composer.json
file - Add
"LaravelFrontendPresets\\PaperPreset\\": "presets/paper/src"
toautoload/psr-4
and toautoload-dev/psr-4
- Add
LaravelFrontendPresets\PaperPreset\PaperPresetServiceProvider::class,
toconfig/app.php
file - In your terminal run
composer dump-autoload
- Run
php artisan preset paper
command to install the Paper Dashboard preset. This will install all the necessary assets and also the custom auth views, it will also add the auth route inroutes/web.php
(NOTE: If you run this command several times, be sure to clean up the duplicate Auth entries in routes/web.php) - Run
php artisan migrate --seed
to create basic users table
Usage
Register a user or login using admin@paper.com and secret and start testing the preset (make sure to run the migrations and seeders for these credentials to be available).
Besides the dashboard and the auth pages this preset also has a user management example and an edit profile page. All the necessary files (controllers, requests, views) are installed out of the box and all the needed routes are added to routes/web.php
. Keep in mind that all of the features can be viewed once you login using the credentials provided above or by registering your own user.
Dashboard
You can access the dashboard either by using the "Dashboard" link in the left sidebar or by adding /home in the url.
Profile edit
You have the option to edit the current logged in user’s profile (change name, email and password). To access this page just click the "User profile" link in the left sidebar or by adding /profile in the url.
The App\Htttp\Controlers\ProfileController
handles the update of the user information.
public function update(ProfileRequest $request) { auth()->user()->update($request->all()); return back()->withStatus(__('Profile successfully updated.')); }
Also you shouldn’t worry about entering wrong data in the inputs when editing the profile, validation rules were added to prevent this (see App\Http\Requests\ProfileRequest
). If you try to change the password you will see that other validation rules were added in App\Http\Requests\PasswordRequest
. Notice that in this file you have a custom validation rule that can be found in App\Rules\CurrentPasswordCheckRule
.
public function rules() { return [ 'old_password' => ['required', 'min:6', new CurrentPasswordCheckRule], 'password' => ['required', 'min:6', 'confirmed', 'different:old_password'], 'password_confirmation' => ['required', 'min:6'], ]; }
User management
The preset comes with a user management option out of the box. To access this click the "User Management" link in the left sidebar or add /user to the url. The first thing you will see is the listing of the existing users. You can add new ones by clicking the "Add user" button (above the table on the right). On the Add user page you will see the form that allows you to do this. All pages are generate using blade templates:
<div class="row"> <label class="col-sm-2 col-form-label"></label> <div class="col-sm-7"> <div class="form-group"> <input class="form-control" name="name" id="input-name" type="text" placeholder="" value="" required="true" aria-required="true"/> @if ($errors->has('name')) <span id="name-error" class="error text-danger" for="input-name"></span> @endif </div> </div> </div>
Also validation rules were added so you will know exactely what to enter in the form fields (see App\Http\Requests\UserRequest
). Note that these validation rules also apply for the user edit option.
public function rules() { return [ 'name' => [ 'required', 'min:3' ], 'email' => [ 'required', 'email', Rule::unique((new User)->getTable())->ignore($this->route()->user->id ?? null) ], 'password' => [ $this->route()->user ? 'nullable' : 'required', 'confirmed', 'min:6' ] ]; }
Once you add more users, the list will get bigger and for every user you will have edit and delete options (access these options by clicking the three dotted menu that appears at the end of every line).
All the sample code for the user management can be found in App\Http\Controllers\UserController
. See store method example bellow:
public function store(UserRequest $request, User $model) { $model->create($request->merge(['password' => Hash::make($request->get('password'))])->all()); return redirect()->route('user.index')->withStatus(__('User successfully created.')); }
Table of Contents
Versions
HTML | LARAVEL |
---|---|
Demo
Profile Page | Users Page | Notifications Page |
---|---|---|
View More |
Documentation
The documentation for the Paper Dashboard Laravel is hosted at our website.
File Structure
├── app │ ├── Http │ │ ├── Controllers │ │ │ ├── Auth │ │ │ │ └── RegisterController.php │ │ │ ├── HomeController.php │ │ │ ├── PageController.php │ │ │ ├── ProfileController.php │ │ │ └── UserController.php │ │ └── Requests │ │ ├── PasswordRequest.php │ │ ├── ProfileRequest.php │ │ └── UserRequest.php │ └── Rules │ └── CurrentPasswordCheckRule.php ├── database │ └── seeds │ ├── DatabaseSeeder.php │ └── UsersTableSeeder.php └── resources ├── assets │ ├── css │ │ ├── bootstrap.min.css │ │ ├── bootstrap.min.css.map │ │ ├── paper-dashboard.css │ │ ├── paper-dashboard.css.map │ │ └── paper-dashboard.min.css │ ├── demo │ │ ├── demo.css │ │ └── demo.js │ ├── fonts │ │ ├── nucleo-icons.eot │ │ ├── nucleo-icons.ttf │ │ ├── nucleo-icons.woff │ │ └── nucleo-icons.woff2 │ ├── img │ │ ├── apple-icon.png │ │ ├── bg │ │ │ ├── fabio-mangione.jpg │ │ │ └── jan-sendereks.jpg │ │ ├── bg5.jpg │ │ ├── damir-bosnjak.jpg │ │ ├── default-avatar.png │ │ ├── faces │ │ │ ├── ayo-ogunseinde-1.jpg │ │ │ ├── ayo-ogunseinde-2.jpg │ │ │ ├── clem-onojeghuo-1.jpg │ │ │ ├── clem-onojeghuo-2.jpg │ │ │ ├── clem-onojeghuo-3.jpg │ │ │ ├── clem-onojeghuo-4.jpg │ │ │ ├── erik-lucatero-1.jpg │ │ │ ├── erik-lucatero-2.jpg │ │ │ ├── joe-gardner-1.jpg │ │ │ ├── joe-gardner-2.jpg │ │ │ ├── kaci-baum-1.jpg │ │ │ └── kaci-baum-2.jpg │ │ ├── favicon.png │ │ ├── header.jpg │ │ ├── jan-sendereks.jpg │ │ ├── logo-small.png │ │ └── mike.jpg │ ├── js │ │ ├── core │ │ │ ├── bootstrap.min.js │ │ │ ├── jquery.min.js │ │ │ └── popper.min.js │ │ ├── paper-dashboard.js │ │ ├── paper-dashboard.js.map │ │ ├── paper-dashboard.min.js │ │ └── plugins │ │ ├── bootstrap-notify.js │ │ ├── chartjs.min.js │ │ └── perfect-scrollbar.jquery.min.js │ └── scss │ ├── paper-dashboard │ │ ├── _alerts.scss │ │ ├── _animated-buttons.scss │ │ ├── _buttons.scss │ │ ├── cards │ │ │ ├── _card-chart.scss │ │ │ ├── _card-map.scss │ │ │ ├── _card-plain.scss │ │ │ ├── _card-stats.scss │ │ │ └── _card-user.scss │ │ ├── _cards.scss │ │ ├── _checkboxes-radio.scss │ │ ├── _dropdown.scss │ │ ├── _fixed-plugin.scss │ │ ├── _footers.scss │ │ ├── _images.scss │ │ ├── _inputs.scss │ │ ├── _misc.scss │ │ ├── mixins │ │ │ ├── _buttons.scss │ │ │ ├── _cards.scss │ │ │ ├── _dropdown.scss │ │ │ ├── _inputs.scss │ │ │ ├── _page-header.scss │ │ │ ├── _transparency.scss │ │ │ └── _vendor-prefixes.scss │ │ ├── _mixins.scss │ │ ├── _navbar.scss │ │ ├── _nucleo-outline.scss │ │ ├── _page-header.scss │ │ ├── plugins │ │ │ ├── _plugin-animate-bootstrap-notify.scss │ │ │ └── _plugin-perfect-scrollbar.scss │ │ ├── _responsive.scss │ │ ├── _sections.scss │ │ ├── _sidebar-and-main-panel.scss │ │ ├── _tables.scss │ │ ├── _typography.scss │ │ └── _variables.scss │ └── paper-dashboard.scss └── views ├── auth │ ├── login.blade.php │ ├── passwords │ │ ├── email.blade.php │ │ └── reset.blade.php │ └── register.blade.php ├── layouts │ ├── app.blade.php │ ├── footer.blade.php │ ├── navbars │ │ ├── auth.blade.php │ │ └── navs │ │ ├── auth.blade.php │ │ └── guest.blade.php │ └── page_templates │ ├── auth.blade.php │ └── guest.blade.php ├── pages │ ├── dashboard.blade.php │ ├── icons.blade.php │ ├── map.blade.php │ ├── notifications.blade.php │ ├── tables.blade.php │ ├── typography.blade.php │ └── upgrade.blade.php ├── profile │ └── edit.blade.php ├── users │ ├── create.blade.php │ ├── edit.blade.php │ └── index.blade.php └── welcome.blade.php
Browser Support
At present, we officially aim to support the last two versions of the following browsers:
Resources
HTML | LARAVEL |
---|---|
Change log
Please see the changelog for more information on what has changed recently.
Credits
Reporting Issues
We use GitHub Issues as the official bug tracker for the Paper Dashboard Laravel. Here are some advices for our users that want to report an issue:
- Make sure that you are using the latest version of the Paper Dashboard Laravel. Check the CHANGELOG from your dashboard on our website.
- Providing us reproducible steps for the issue will shorten the time it takes for it to be fixed.
- Some issues may be browser specific, so specifying in what browser you encountered the issue might help.
Licensing
Useful Links
Social Media
Creative Tim:
Twitter: https://twitter.com/CreativeTim?ref=pdl-readme
Facebook: https://www.facebook.com/CreativeTim?ref=pdl-readme
Dribbble: https://dribbble.com/creativetim?ref=pdl-readme
Instagram: https://www.instagram.com/CreativeTimOfficial?ref=pdl-readme
Updivision:
Twitter: https://twitter.com/updivision?ref=pdl-readme
Facebook: https://www.facebook.com/updivision?ref=pdl-readme
Linkedin: https://www.linkedin.com/company/updivision?ref=pdl-readme
Updivision Blog: https://updivision.com/blog/?ref=pdl-readme
Credits
via Laravel News Links
Paper Dashboard Laravel – Free Frontend Preset for Laravel
How to setup automatic db backup in Laravel
Hi All, this is Adi again with a Laravel related article. This time in a shorter format. As Laravel developers we need a way to back up our app’s databases somewhere for both save keeping the data and for analysis. I want to share with you a simple solution that I have devised for some of my smaller projects. I have tested this method only on MySql DB and on a VPS, but I think it’s pretty much the same for any database.
TLDR;
The outline of my solution is as follows. There’s an artisan command which handles the backup, that runs periodically using a cron. This command makes use of the mysqldump
tool that comes with all MySql installations. mysqldump
dumps the given DB into a .sql
and we can control where it is dumped. And that’s how my solution works. Now let’s see some code.
The Code
First off create an Artisan command like so php artisan make:command BackupDatabase
. This should create a class with the name you mentioned in the command and should also have some default scaffolding for the command.
Let me explain what the above code does. Within the constructor we prepare the name of the file (line 20), then we check if there’s a folder named backups
within the storage folder, if not we create it (line 21). Then we instantiate a process, with the command that we want to be executed, we also pass it other details (line 23-29).
Then in the handle method runs the process and logs the output to the application logs. This handle method is executed after the constructor by Laravel itself, so you don’t have to invoke it from anywhere.
And finally you need to setup cron, you have 2 options here, either you can call Laravel’s schedule:run
command or call your backup command directly.
Conclusion
This is a pretty simple and neat solution for backing up your most valuable asset, that’s the data. You can extend this feature to do more, like attach the .sql file to an email or upload it to dropbox or where ever and so on.
That’s all from me, it’s been Adi – more about me at Simplest Web.
Related resources
via Laravel News Links
How to setup automatic db backup in Laravel
Create a simple report in Laravel
Published: Sep 27, 2019 by C.S. Rhymes
Recently I was tasked with creating a report in a Laravel project and I thought I would share some of the things I learned along the way. I’m going to use a shop as an example with an orders table that contains the orders, but these principles should apply to pretty much any report. Firstly I want to get the number of orders for the previous week and then I want to get a count of orders by week and year so I can put this data into a report.
Orders last week
The first request is to show how many orders there have been in the past week. Sounds simple right, but even this has a few challenges you need to be aware of.
We could start by creating a query that filters the orders that are greater than the start of the week and less than the end of the week.
$ordersLastWeek = Order::where('created_at', '>', '2019-09-16') ->where('created_at', '<', '2019-09-22') ->count();
This returns us a number thanks to using count() instead of get(), but we have hard coded the dates in our query which is less than ideal as we would have to change the query each week.
Luckily we can make use of Carbon to automatically calculate the start and end dates for our query. We can start by finding the current date and time using now(), then subtract a week and then find the start of the week and the end of the week. We can also tell the database we only want the created_at column in this query by adding a select() rather than getting all of the fields in the order.
$ordersLastWeek = Order::select('created_at') ->where('created_at', '>', now()->subWeek()->startOfWeek()) ->where('created_at', '<', now()->subWeek()->endOfWeek()) ->count();
If we wanted to display the orders from the week before last we can change subWeek()
to subWeeks(2)
.
Orders By Week
Now we need to get a little more complicated. We need a count of orders for each week and year.
I initially thought I could make use of the count() method like the previous query but it turns out this doesn’t work as I had expected. I could return the count of all orders, but I couldn’t use it with groupBy().
If I only had a few orders I could get all of the orders and then loop through them with some collection methods in PHP to calculate the week and year for each item and then group them how I wanted.
// Please don't do this $ordersByWeek = Order::all()->map(function($item) { $item->week = $item->created_at->weekOfYear; $item->year = $item->created_at->year; return $item; }) ->groupBy(['year', 'week']) ->map ->map(function($week) { return $week->count(); });
Just to explain, I’m getting all the orders, then looping through each of the orders and set the week and year using carbon methods based on the created_at, before grouping by year and week and then looping through the weeks and returning a count of the orders for that week.
This works, but its not very efficient and could start using a lot of memory very quickly as the number of orders starts to grow. Instead, we need to make use of the power of the database. The rest of the article assumes you are using mysql as your database connection as different databases may need slightly different syntax or methods, but the principles should still apply.
We need a way of querying the database to get a count of orders. We can make use of DB::raw() in our select statement to count the order ids. To do this we need to use a mysql aggregate function called count(). We then give this the name of quantity using as
.
DB::raw('count(id) as quantity)
We can use DB::raw() once more to get the week number and year from the created_at date using mysql’s year() and week() methods.
DB::raw('week(created_at) as week')
We can then group by the calculated year and week values to get the quantity of orders for each year and week.
use Illuminate\Support\Facades\DB; $ordersByWeek = Order::select([ DB::raw('count(id) as quantity'), DB::raw('week(created_at) as week'), DB::raw('year(created_at) as year') ]) ->groupBy(['year', 'week']) ->get() ->toArray(); return $ordersByWeek;
The toArray() method on the end converts the result to an array to simplify the response. Something like the below would be returned in a json response format.
[ { "quantity": 3, "week": 36, "year": 2019 }, { "quantity": 2, "week": 37, "year": 2019 } ]
You could further customise the above query to only show a particular year by using the when() method. This checks if year is in the request() sent to your controller. Laravel has some handy tools for comparing dates built in, such as whereDate(), whereMonth(), whereDay() and whereYear().
$ordersByWeek = Order::select([ DB::raw('count(id) as quantity'), DB::raw('week(created_at) as week'), DB::raw('year(created_at) as year') ]) ->when(request('year'), function ($query) { $query->whereYear('created_at', request('year')); }) ->groupBy(['year', 'week']) ->get() ->toArray();
The when() method also allows you to set a third parameter which will run if the test returns false, so you could filter by the current year by default if year is not in the request().
$ordersByWeek = Order::select([ DB::raw('count(id) as quantity'), DB::raw('week(created_at) as week'), DB::raw('year(created_at) as year') ]) ->when(request('year'), function ($query) { $query->whereYear('created_at', request('year')); }, function ($query) { $query->whereYear('created_at', now()->format('Y')); }) ->groupBy(['year', 'week']) ->get() ->toArray();
Hopefully this post has provided you with a starting point to start accessing some key metrics from your Laravel project and show you how you can refactor your queries to make them a bit more reusable, especially by using the when() method, instead of having to write separate queries for similar requests.