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!
Trailers Everywhere, But No Empties
2023-03-05
Apparently there is a shortage of empty trailers in the Atlanta area, we have run around for hours trying to find one. We contacted the terminal after the last failed location and were told to wait while they contacted someone, and spent the rest of the day waiting. After a little bit of a waiting at that location we realized we were really close to the Atlanta terminal, so we hopped on over. We got some laundry done, went on walks with the animals, rode the One Wheels, and watched some more One Piece. It ended up being a pretty chill day.
DataTables.net Quick And Dirty
2023-03-04
I got DataTables working, but not the Laravel DataTables. In Yajra's introduction it does specify that Laravel DataTables is a package that handles the server-side works of DataTables using Laravel, and provides links to to source. I followed them to datatables.net an started reading through the manual. There are some quick lines of code that you can add to your HTML to get a quick and dirty implementation of DataTables going. The view in question should have the following lines of code added:
<script src="https://code.jquery.com/jquery-3.6.3.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.3/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/1.13.3/js/jquery.dataTables.min.js"></script>
<script>$(document).ready( function () {
$('#myTable').DataTable();
});</script>
The table in that view should be setup as such:
<table id="myTable" class="display"> {{-- the display class was not needed for my table, but might cause issues for other implementations if it's not there --}}
<thead>
<tr>
<th>Heading</th>
...
</tr>
</thead>
<tbody>
<tr>
<td>Content</td>
...
<tr>
</tbody>
<tfoot> {{-- Footer is optional, but DataTables can still work with them --}}
<tr>
<th>Heading</th>
...
</tr>
</tfoot>
</table>
Note that DataTables says it can work without the <thead> or <tbody> elements, but I had to add those in for it to work. Also note that this implementation of DataTables only works with the data that has been sent to the view, although at a quick blush it works well. It is only client side, and as is cannot request anything new. If you are working with large amounts of data this can be a problem for data transfer and client processing. I did look into the server side implementation and am a little ashamed to admit that I am not so keen to take a whack at it, as it means understanding a few more coding languages better than I current do. Also, from what I have seen DataTables does not have any kind of export option, which Laravel DataTables does. So now I think I am back to upgrading my project.
https://yajrabox.com/docs/laravel-datatables/10.0/introduction
https://datatables.net/
DataTables Dependency Conflicts
2023-03-03
A bit of a hiccup, DataTables has a dependency conflict with another package that has not been easily resolvable. The issue is that something in the 'composer require yajra/laravel-datatables:^*.*' install won't accept an illuminate/database version above 5.*. I might not need all of the extra packages, which opens up the command 'composer require yajra/laravel-datatables-oracle:"^*.*"'. The potential issue there is that the lower versions of DataTables which are theoretically compatible with my version of Laravel still have dependency conflicts. And the version that was suggested to fix the dependency issues might not actually support my version of Laravel, although it seems to have installed just fine.
https://stackoverflow.com/questions/73107925/requirements-could-not-be-resolved-to-an-installable-set-of-packages-yajra-lara
composer require yajra/laravel-datatables-oracle:^9.21.2
If this doesn't work, then I'll probably need to look at updating to a/the newer version of Laravel. At that point I might just start a whole new project so that everything is clean and more or less copy the rest of the code over.
Taxes And DataTables
2023-03-02
Took a minute to get started organizing tax documents, and of course we are missing a few things. but the important thing is that it has been started, companies have been contacted, and it's now on the to-do radar. In my opinion taxes are far too complicated. It's not too bad when you're single, worked only one job, and don't really have anything else going on. However, every additional thing multiplies the complexity; married, student anything, house, incentive programs, moving jobs, working out of state, and all kinds of little nuances. What's more is that we are the ones in charge of determining how much we owe, but if we get it wrong there are penalties and possible jail. Yet the one's that know what we owe won't just tell us. It's like a math class gone horribly wrong. Anyway, working on taxes. Also, started looking into providing export capability for the data that is currently in the view. After some solutions that worked mainly off of feeding data from the DB instead of the view I decided to contact my Guru. He pointed me to Laravel DataTables from Yajra Box, which provides an excellent solution for tables in general, including pagination, sorting, filtering, formatting, and several export options.
https://yajrabox.com/docs/laravel-datatables/10.0/
I have my focus for the export upgrade now.
Licensed To Massachusetts
2023-03-01
It's official, we are Massachusetts residents. We swung by and picked up our new licenses from the PO. The car had some water get into the engine compartment... and into the battery compartment... and completely drain the battery. Luckily there was a guy there who was willing to jump the car. Once it was started though, ran like a champ. Also got the swing by Sweet Piglet to get some Bobba Tea and sweets. We like their goodies and personality.
More Boats
2023-02-28
Speaking of boats, one of the sailing YouTube channels that I have taking a liking to has been Sailing SV Delos (https://www.youtube.com/@svdelos). They have been documenting their adventures since their first big trip across the Pacific in 2010. They were still pretty new to sailing at that point, just heading down the West coast of the US prior. I like seeing the cool places they find, the people they run into, and the trouble they encounter along the way. They give a decent perspective of what boating is like for them, although they live a different lifestyle then we do. There are still a lot of parallels that make them relatable and they still show what to expect from the oceans.
Boat
2023-02-27
We've been working on getting through One Piece, but there are a lot of episodes. The show follows a small but resilient crew of extraordinary pirates as they seek out adventure, treasure, and the "One piece". It's a show that helps give us the motivation to work toward getting our own boat. Sailing seems like a great adventure and way to break away from everything. It's going to have a lot of challenges that we've yet to really encounter, but from what we've seen not much different from first time home owning. Maybe higher stakes if thing go too wrong, lol.
Laravel Compound/Composite Index/Unique And Other Reminders
2023-02-26
Also in implementing Laravel Socialite I ran across an interesting migration bit, making table column combinations unique:
$table->unique(['user_id', 'provider_id']);
https://laracasts.com/discuss/channels/requests/complete-register-and-login-app-with-socialite-and-multiple-providers?page=1&replyId=76774
This is supposed to put a constraint that will make sure that there is only one set of the combined column values. You would be allowed to have the same user_id several times in that column, and several of the same provider_id in that column. But the combination of user_id and provider_id will only have one. In the Laravel docs they do mention the compound or composite index, but don't mention that it can be used with the unique() method. Do be sure to wrap the columns inside of the square brackets [] otherwise Laravel will interpret the second argument as a user provide index name.
https://laravel.com/docs/10.x/migrations#creating-indexe.
Some other reminders,
Some code to check the existence of an index key:
https://stackoverflow.com/questions/30504939/check-if-a-unique-index-key-exists-in-laravel
The Eloquent queries can chain together to make ANDs with ->where()->where() as well as ORs with ->orWhere()->orWhere(). This is not really in the Eloquent section, but rather the Database -> Query Builder section.
https://laravel.com/docs/8.x/queries#basic-where-clauses
PHP function to upper case the first word of a string:
ucfirst($value);
https://www.php.net/manual/en/function.ucfirst.php
"Upgrade" PHP Versions In Windows
2023-02-25
When installing Laravel Socialite I did have an issue with my PHP version, I needed 8.1 and had 8.0. Keep in mind that It wasn't Homestead or Forge that had this issue, but rather my PC itself. To "upgrade" PHP versions there are 4 basic steps:
1. Download new PHP.
2. Update the Path Environment Variable.
3. Copy or modify the php.ini file.
4. Restart any open Console windows.
Download PHP from the PHP creators, unzip, rename if wanted, and move to desired location:
https://www.php.net/downloads.php
Search for "environment" until "Edit the system environment variables" shows, click on it, go to "Environment Variables", select "Path" then "Edit", add new PHP folder path.
https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/
If you have made any adjustments to the PHP options in the previous php.ini file, such as uncommenting the "extension=php_openssl.dll" line... You will want to copy over the old php.ini file from your previous PHP version, or modify a new one.
https://stackoverflow.com/questions/35249620/the-openssl-extension-is-required-for-ssl-tls-protection
And the one more import thing to do to have the changes take effect, restart any open console windows so that they will get the new Path Environment Variable, and know where the new PHP version is.
Implementing Google Sign In
2023-02-24
I've been working on integrating logging in with Google, this is relatively easy with Laravel's Socialite:
https://laravel.com/docs/8.x/socialite
I did initially use this site, which walks you through a basic setup but with outdated Google Developer Console instructions:
https://medium.com/employbl/add-login-with-google-to-your-laravel-app-d2205f01b895
For better Google Developer Console instructions, this site is more relevant:
https://shouts.dev/articles/laravel-socialite-login-with-google-account-with-breeze
There are many different ways to handle the callback and what you do with the information provided by the social provider. This sites I referenced do more of a simple check against just the email or Google ID, which they include as another column in the user table. This way seemed a little overly simple, and messy for the user table. After doing a little bit of searching for a more thorough socialite integration backend setup I ran across this thread, which is a little dated for the code but has solid concepts:
https://laracasts.com/discuss/channels/requests/complete-register-and-login-app-with-socialite-and-multiple-providers
I liked the general consensus that the social profile information should be in it's own table and tied to the appropriate user ID as well as the providers, in their own table too. This seemed like a good way to allow flexibility to add more social providers, and have them all be able to be linked to the same user on my site. This does assume that each of the social accounts use the same base email, which I will probably look into allowing the linking of multiple emails and checks to see if social emails have changed. I did notice in the provided information that Google provides a 'verified_email' Boolean, soo I threw in a quick conditional on that as well. So in my callback I ended up with something like:
try {
$socialUser = Socialite::driver('google')->user();
} catch (\Exception $e) {
return redirect('/login');
}
if($socialUser->user['verified_email']){
$spid = SocialProvider::where('name','like','Google')->first()->id;
$socialProfile = SocialProfile::where('provider_id', $spid)->where('social_id', $socialUser->id)->first();
if(!$socialProfile){
$user = User::where('email', $socialUser->email)->first();
if(!$user){
$user = new User;
...
$user->save();
event(new Registered($user));
}
$socialProfile = new SocialProfile;
...
$socialProfile->save();
}else{
$user = User::where('id', $socialProfile->user_id)->first();
}
if($user){
auth()->login($user, true);
return redirect()->intended("/user");
}else{
return redirect('/login');
}
}else{
return redirect('/login');
}
}
Oh yeah, I also stole the "event(new Registered($user));" code from the Laravel Breeze registration controller to trigger the email verification email. Since my code currently checks that, and it still seems like a good thing to have in place.