Rants and Raves

Welcome to Rants and Raves! I kept hearing that I needed to write, so here is the blog that I ended up starting. It is mostly an accounting of my progression through creating a web site, nuances with code, and tips about what I did to make things work. In there you will find sprinkled about some gems of life, and letting loose fun. Enjoy!

Laravel Eloquent DB Query Find Null Entries
2022-10-27
After adding a post date column in my table, I am going to need to fill in dates to use that to sort on. Instead of manual I want to learn more of Laravel's database queries and Eloquent. First grab the entries with NULL post date. The Controller: $data['null_count'] = DB::table('Blogs')->whereNull('post_at')->count(); Verify that the query worked in the View: <p>Blog count of how many entries have null post dates: {{ $null_count }}</p> https://laravel.com/docs/8.x/eloquent
Add New Column To A Table In PhpMyAdmin
2022-10-26
There are several way to do this: 1. Tree -> DB -> Table -> Columns -> New -> Fill out info 2. Select Table in tree -> Structure tab -> Go button in section under list of columns -> Fill out info 3. Select Table in tree -> SQL tab -> ALTER TABLE `table` ADD `name` VARCHAR(1000) NULL ; I needed to add a posted column to help keep the created column accurate now that I'm filtering out future posts.
Limit Showing Blogs By Current Date
2022-10-25
Now I can get ahead on making posts without a bunch dropping at once. Just a couple of tweaks to the controller. I adjusted the sort key too. Controller: Add: use Carbon\Carbon; Modify: $data['blogs'] = DB::table('Blogs')->orderBy('id', 'DESC')->paginate(10); To: $data['blogs'] = DB::table('Blogs')->where('created_at', '<=', Carbon::now())->orderBy('created_at', 'DESC')->paginate(10); https://stackoverflow.com/questions/44266337/laravel-eloquent-where-date-is-equal-or-greater-than-datetime
Pagination Navigation Prettier
2022-10-24
I was able to clean up the pagination navigation with a couple of additions to the App\Providers\AppServiceProvider.php file. use Illuminate\Pagination\Paginator; and Paginator::useBootstrap(); Remember, it is different for Laravel 9. https://laravel.com/docs/8.x/pagination#using-bootstrap
Check Your Laravel Version
2022-10-23
Just in case you have forgotten which version of Laravel you are working with and realize you are likely looking at the wrong documentation, like I may have... You can verify your current version in the ./vendor/laravel/framework/src/Illuminate/Foundation/Application.php file. Or with the php artisan --version command, I think you will need PHP installed for that one. https://tecadmin.net/check-laravel-version/
Pagination Started
2022-10-22
It's not pretty, but pagination worked! Now the blog doesn't just dumps 10 at a time. Controller Add: use Illuminate\Support\Facades\DB; Modify this: $data['blogs'] = Blog::orderBy('id', 'DESC')->get(); To: $data['blogs'] = DB::table('Blogs')->orderBy('id', 'DESC')->paginate(10); View Add: {{ $blogs->links() }} Laravel has multiple ways of doing so DB might not be necessary. I'm going to leave it since I have to wait 20 minutes to test a change. https://laravel.com/docs/9.x/pagination
Azure Push Delays Are Bad For Test Environments
2022-10-21
I'm going to need to install a dev environment. It's taking about 20 minutes to push the site to Azure. That not bad... I guess. Except when it's test time for new things, like pagination that I have started playing with. Already I've had one push fail likely from cell tower issues while travelling. Two succeed just to tell me I did it wrong. And now I'm on to a third that will hopefully work. That's an hour and twenty minutes of waiting to check 4 lines of code change. I need a dev environment.
Hyper-V Breaks Sleep For Alienware
2022-10-20
Turns out that my Dell Alienware M15 R7 has some sleep issues. And by that I mean it wouldn't sleep, at least not properly. Often the lights and/or the fans would stay on. The entire thing would stay hot even after the night. On battery I would come back to a system error about not starting properly, and have to restart. The Alienware Command Center said it couldn't do because of Hyper-V. After disabling Hyper-V sleep seems to be working a lot better, at least it stays cool now.
New Feature: Most Recent First
2022-10-19
Up until now the blogs have been posted with the most recent all the way at the bottom, but now they are at the top. In the Laravel controller I had grabbed the blogs in order with: $data['blogs'] = Blog::all(); I am now grabbing the blog data in descending order with: $data['blogs'] = Blog::orderBy('id', 'DESC')->get(); With the data in reverse order the for loop also spits it out in reverse order. https://stackoverflow.com/questions/17553181/laravel-4-how-to-order-by-using-eloquent-orm
PS Get-Location
2022-10-18
Power Shell has a cmdlet called Get-Location that returns the current working directory. Comes in handy when you need to navigate directories beyond where a PS script is located. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-location?view=powershell-7.2
Id Title Body Post At