okay so in this episode we are actually going to create new posts that means we
are having this forum and in this form we will fill the data and save
everything on the database so with that i'm your host arthur and this is the
channel at about level and the cool T word level someone has posted me and he
said that I am incorrect for the pronunciation of the level it's
allowable and I am saying level so I apologize because I actually don't know
what the actual pronunciation so I think it doesn't matter because this means we
love level laravel it doesn't matter so I will try to change my accent and try
to call it laravel but again level is in my habit and I will try to change this
and please promise me whenever I say level so laravel so laravel and don't
forget subscribe and like betweens on Facebook Twitter Instagram so let's
create and in ours level block series let's begin so we have all these things
we have created this many routes here we have created users here so sidebar close
Edward go stack yeah so now we want to have data here and whenever I click
Submit this submit button I want to submit this
data in our contour database so here is the database so where is that block
series we have given and here is the who's table yeah so here is the post
table so let's just create that thing and we will see how we can move forward
so let's first see what we are getting on that page so I will go to admin post
and here is the post dot blade so here where we have formed
home form form yeah here's the phone but it's only for text area what we need
that form for whole of that thing so yeah this is the form and that form is
starting we're here so role is form action yeah it's very
important action is that we're on which route or on which function you are
actually posting your data so I will say again as we always do I will say route
route name is because we are going to post dot to create so think the missed
one more yeah so let's just open app content EP controller admin post
controller so here we have so here we are returning this and now we have to
store so instead of create I have given I have to give a store here so this will
go to this function the data from the form will come here because you can see
here it request request so this is the request function which is having
everything from the form inside this request array so this thing is here and
now we have to give the method which is post and the most important thing
because we are on laravel and we need to say CSRF underscore field also here so
otherwise we will get error so let's see first name we have titles second name is
subtitle we have a good name love's name is here file is here checkbox yes
status and it's a body which button is is okay that fills the close button okay
and here the body everything is here so let's do one thing here inside this
store I will return what required to request arrow all so
everything inside request I am going to return so actually what's happening here
let's just firstly refresh this page give it this is with first title
subtitle is simply subtitles doesn't matter
this is title okay and I don't want to choose any file for now body is simply
body let's just submit it and sexy what happened okay you know what
it's not working because we are on user create we have to say here
post slash create okay and now let's try to submit it and yes we have everything
null so now type here the title okay so now type here this is post title and the
title simply slug and no no that will not this yes same thing submit it and
you can see we have everything here so we have body here we have a national
yeah okay slow subtitles subtitle and title okay that means that will be for
WYSIWYG HTML 5 that means this text area some kind of things okay it doesn't
matter we don't have to store these things okay so we have these things and
these things is here because on our let's open that the post controller we
are returning requests all so now what so now what I have to do I have to
create these new things but before creating I have to validate this thing
so that everything is here and user cannot submit the form until and unless
he has filled all these things so let us fuck Lee do this so I will say
this arrow validate and inside here I have first argument as request and
second is the same validation so firstly the title will have required field so
required and subtitle also required to required and same thing for slug and
also body okay so these are the things and the important importance of this
validation is that whenever you are submitting this form empty it will
return back to the same route you don't have to say if validation fail return to
that original route know it will smart enough to return to that page with
errors so what actually I can do I can open here and above the form just where
above the form here after this titles I will say here firstly if count dollar
error having greater than zero then inside that I think here we will create
a for each loop which says errors arrow all will get error okay and for every
error I want to show inside a P tag which
having class of alert alert to danger and just echo out the error save this
file go back refresh and submit it and yes you can see it's having these all
these errors health okay so this is I think the most unique
thing so we don't have to say anything it's just saying the title field is
required the title field is required plugs and this is coming from the name
if I give this my title name as my title okay refresh and submit you can see okay
okay yeah because it I have to pay here also
that why giving okay my title is required so submit and yes my title is
required so these other things you can change it okay so it's here and let's
now create this form after validation we have these validations now we have to
create this so firstly what we want for creating anything we need to connect to
database and for dealing with the database we need model you know in the
in one of our episode we have created the model so now we have to call that
model so the model which are using for the post is currently the post model so
for the post model we are going to create we are going to create or even
you can use like this so I will say dollar post we we will create new
instance of this post model and I will say post arrow title is equal to request
arrow title title Oh
tighter okay and same thing for slug or subtitle for body so firstly this one
which is sub title then we have this one so we can say slug then we have this one
which is body and after that we can save Post Arrow save okay and it
will save everything into your database so these other things so let's see we
have connected the database actually we have connected because we have all these
migration created so yes we have these things so let's just do one thing go
here fill these forms I will refresh it error are gone and now this is first
title yeah you're right you're right anything wishes okay and this is first
title make it bold and make it italic move it here oh right what moving yeah
move it here and this good okay so now submit and it's having error so this is
giving error because it doesn't know what the post is actually if we have to
import it at the top like we have requests we have controller so I will
use this PHP companion so I will say use and you can see page be campaigning fine
use it will just import this at the top and if you're not familiar with this you
can check out the sublime series I have and link is in the description so I will
say use it at the top and you can see oh it's not given okay ah yeah because it's
a small V now let's find it few here so now we have this use it at the top yes
it's here so these are the things so that's why it's not it okay so go
refresh again and it's saying all lots of things if status doesn't have
different default value whenever you say you will feel this kind of error you
will have to look for your database and you can see the status we are not
providing and it's having null value so whenever we are not providing null value
we want to have default of 0 and again we can allow null for image
and posted by also we can allow it to be null for now and like and dislike also
okay so these are the things we can allow to be null but these things cannot
be null okay so go here refresh and yes we are having no air that means we are
having data on our database but what is blank page the first because after
saving we have not read redirected anywhere so just return redirected and
after that we want to redirect to that create route so instead of here elegance
a route of post dot create no post dot post dot index will be fine
post dot in the semicolon is here so refresh continue and yes we are on the
post dot index that in the show the index function of the post controller so
now we have two fields here so this is because the blog in the middle of thing
but whenever you redirect here so that will be never going to happen this two
kind of same thing in the database so this in this way we can save the data
inside post and in the next episode we are going to create these things for
category and tag and we will move very fast and I think it's not very fast but
we will move step by step so I think you are liking this series and if you liked
please give it thumbs up please share this videos with your developer friends
so that everyone know how you can use the level to create big project and
don't forward subscribe and like bit fumes on Facebook Twitter and Instagram
and we will meet in the next episode till then bye bye okay bye
Không có nhận xét nào:
Đăng nhận xét