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!
Azure Using Old Data
2022-12-06
It seems there is a long ongoing issue where Azure seems to use a cached version of a site. For me it is affecting at least my frame blade for my views. Even though the updated one has been successfully uploaded, Azure insists on using the outdated one. I have adding some site config settings, and manually stopping and restarting, but to no avail. After I uploaded another change to the frame blade it finally worked again... Days later.
Make Form Easily Accessible
2022-12-05
Now that all of the pieces are in place there is one last thing to do, provide an easy like to get to the new form. For now, inside of the sidebar section in the blog blade I placed the following:
<a href="/blog/create">New Blog</a>
Now I have a simple interface to add new blog entries. Now that I'm using Laravel to write to the database, I no longer need to worry about setting the created or updated date.
Update Blog Controller Store Function
2022-12-04
The form will submit the data supplied to the blog/post page via the action and method. The route interprets that as the blog controller with the store function. The store function needs added:
$blog = new blog;
$blog->title = $request->title;
$blog->body = $request->body;
$blog->post_at = $request->post_at;
$blog->save();
return redirect('/blog');
Create a new instance of a blog model, put form data into it, save it, then go back to the blog page.
New Create Blog View
2022-12-03
With the route and controller set, we need to actually make a view called blogCreate.blade.php in the views directory.
<form method="POST" action="/blog">
@csrf
<div class="form-input">
<label>Title</label> <input type="text" name="title">
</div>
<div class="form-input">
<label>Body</label>
<input type="text" name="body">
</div>
<div class="form-input">
<label>Post Date</label>
<input type="date" name="post_at">
</div> <button type="submit">Submit</button>
</form>
Test Of New Create Page
2022-12-02
If this gets recorded, then the code works to have Laravel write to the database.
Use The Controller To Route To A New Page
2022-12-01
With some of navigation nuances fixed, we can work on a new page to create blog posts. In the blog controller in the Create() method we need to add:
$data['title']='Create a Post';
return view('blogCreate')->with($data);
Now when you navigate to /blog/create the route will go to the create function of the controller, and that function will know which view to use.
Relative Hyperlinks
2022-11-30
Another thing that caused issues with using subpages was the relative paths that were being used for the links. I was using ./ in front of my paths to the pages. After going to the blogs/create page the main links would put blogs before themselves. so trying to go back to the blogs page would try to do blogs/blogs which doesn't exist. To fix I just had to remove the . and just use /.
./ - Relative to current directory.
/ - Relative to root.
Gap Filling
2022-11-29
At some point I had a double database entry, so I deleted one. Since then there's been a gap that I am now filling up. This will be post 48. Because of the assigned post date, it will show up between post 99 and 100. I did this because i don't like having data gaps, but that might not be suitable for other setups.
Better Route Config?
2022-11-28
Ran into some issues when trying to use the subpage capability of the route and controller. In the web.php the blog route was:
Route::get('/blog', [BlogsController::class, 'index']);
That is only one very specific route. To use Laravel's auto route ability for various controller functions like create it needs to be:
Route::resource('/blog', BlogsController::class);
Grab By Post Date Instead Of Created Date
2022-11-27
Now that all the posts have had their post date field filled in, the Eloquent query needs adjusted from:
Blog::where('created_at', '<=', Carbon::now())->orderBy('created_at', 'DESC')->paginate(10);
To:
Blog::where('post_at', '<=', Carbon::now())->orderBy('post_at', 'DESC')->paginate(10);
This is something that should not be noticed by the front end as the created date and post date are currently the same.