Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,540 --> 00:00:02,810
Now that we have the working Post model,
2
00:00:02,810 --> 00:00:06,780
we can finally save the submitted blog posts to the database.
3
00:00:07,080 --> 00:00:11,650
I will first import the Post model in the Post controller file.
4
00:00:11,850 --> 00:00:15,960
The Post model is inside of the App\Models directory.
5
00:00:16,940 --> 00:00:21,160
And now I will scroll down to the store action because that is
6
00:00:21,160 --> 00:00:24,170
where we actually need to store the blog post.
7
00:00:24,410 --> 00:00:27,590
I don't want to store posts which don't pass validation,
8
00:00:27,590 --> 00:00:30,760
so let's use this model after the validation code.
9
00:00:31,140 --> 00:00:35,550
First, we need to create a new Post instance of the post model.
10
00:00:35,940 --> 00:00:39,440
This will create a new empty post object and this is
11
00:00:39,440 --> 00:00:42,940
exactly what we need because we need to create a new post
12
00:00:42,950 --> 00:00:45,260
before we store it to the database.
13
00:00:45,940 --> 00:00:49,440
I can now assign the user input from the request to the
14
00:00:49,440 --> 00:00:51,850
post object properties of the same name.
15
00:00:52,840 --> 00:00:57,550
These properties were dynamically created from the columns of the post table.
16
00:00:58,340 --> 00:01:02,810
And now to actually save this new post instance to the database,
17
00:01:02,820 --> 00:01:05,150
I can just use the save method.
18
00:01:05,269 --> 00:01:09,420
Everything you do with model objects in the code will stay in
19
00:01:09,420 --> 00:01:13,270
temporary memory until you actually use the save method to
20
00:01:13,270 --> 00:01:15,350
commit the changes to the database.
21
00:01:16,440 --> 00:01:19,460
And let me also modify this flash message.
22
00:01:19,840 --> 00:01:23,070
Instead of getting the title and description from the request directly,
23
00:01:23,070 --> 00:01:25,560
we'll get them from the post object itself.
24
00:01:26,640 --> 00:01:29,960
Now let's test if all of this works as expected.
25
00:01:30,440 --> 00:01:32,450
Open the Create Post page.
26
00:01:32,840 --> 00:01:36,020
I will input some random title and description here.
27
00:01:36,030 --> 00:01:39,860
Don't forget that description should be more than 10 characters long.
28
00:01:40,840 --> 00:01:45,280
After I submit this, the post should be saved to the database.
29
00:01:45,580 --> 00:01:49,340
There are no errors and this flash message looks correct so
30
00:01:49,340 --> 00:01:51,830
hopefully everything worked as it should.
31
00:01:52,180 --> 00:01:56,760
I will take a look at the posts table from the phpMyAdmin interface,
32
00:01:57,440 --> 00:01:58,610
and here it is.
33
00:01:58,620 --> 00:02:01,180
This is the blog post I submitted.
34
00:02:01,260 --> 00:02:04,060
It is successfully saved to the database.2909
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.