PUT/DELETE are now allowed as form methods in Laravel v6.4.1: and the routes work fine this way also. in edit.blade.php {!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!} in show.blade.php {!! Form::open(['action' => ['PostsController@destroy', $post->id], 'method' => 'DELETE']) !!}
hey bro..from Kenya here..you made me well conversant with Laravel,Thank you for the tutorial..Imma add myself to your subscribed users as a token of appreciation.
The Best Course ever for me, I traveled through UA-cam searching for Laravel Tuts, all i found are Hindi but also not suitable for me and too long, this one is the best !!!, thanks man
Hi Brad. I am from Pakistan..I got tears in my eyes dear when I gonna executes codes smoothly....I always pray for you brother...compact and reasonable series....thanks bro..Allah bless you always. Ameen
To keep the method even simpler, you could identify the post on the method construct. instead of public function destroy($id) { } you could use public function destroy(Post $id) { } This replaces the $post = Post::find($id); By the way, your tuts are awesome. Keep it up mate!
This is the part where it gets a little confusing for noobs like me. That being said, this series is pretty amazing. I think that your delivery is spot on. Thank you so much for sharing your time and knowledge with us. Much appreciated. Peter
Have to say this is the best Laravel series there is. And I have tried 2 series earlier to this and just left them in the middle because they were either boring or way to fast, to my liking.
This would be the full line of code: {!!Form::open(['action' => ['App\Http\Controllers\PostsController@destroy', $post->id], 'method' => 'POST', 'class' => 'float-right'])!!} StackOverFlow: stackoverflow.com/questions/47121605/postscontrollerdestroy-not-defined-in-laravel/64236027#64236027
3:46 Using ck-editor form you actually can use 'method'=>' _PUT_ ' in place of 'method'=>' _POST_ ' instead of adding a __method_ hidden field. It will be automatically spoofed by sending a _method hidden field along with the submitted data.
-c copies an entire line when nothing is selected (equal to yy in vi) -v pastes the line again above the cursor (equal to p in vi) -x deletes an entire line (equal to dd in vi) those commands makes editing so much faster btw... great videos
The code below works fine dont need to add that hidden form thng Edit Post {!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!} {{ Form::label('title', 'Title', ) }} {{ Form::text('title', $post->title, ['class' => 'form-control', 'placeholder' => 'Title']) }}
I know this is old, but if you're like me you can't stand that the application redirects to the post list after creating and updating posts. If you're in the same boat, update your return line in the store method in PostsController.php to: return redirect()->route('posts.show', ['post' => $post->id])->with('success', 'Post created!'); and also update your return line in the update method to: return redirect()->route('posts.show', ['post' => $id])->with('success', 'Post updated!');
I don't think that would work... If you want to have your application redirects to the newly created post, just add the id from the Post object to the URL: return redirect('/posts/'.$post->id)->with('success', 'Post Created'); And if you want to do the same thing with the Update controller: return redirect('/posts/'.$post->id)->with('success', 'Post Updated');
@@sasajovicic2384 what you think is irrelevant. If you want to be helpful then test it and THEN see if it works or not. Because in this case it works just fine and is actually the recommended way of doing this (see laravel documentation)
It's works very well. Thanks in advanced but I had one question, why I can't use this way 'posts/show'? because I get an error when used this way. I must used this way 'posts.show' and no errors.
In laravel 6 Laravel Collective, you can directly use {!! Form::open(['method' => 'PUT', 'action' => ['PostsController@update', $post->id] ]) !!} PUT and DELETE methods will now be spoofed automatically
if you are getting The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. then all you can do is {!!Form::hidden('_method','PUT')!!} use this instead of {{Form::hidden('_method','PUT')}} . the first one works well
great series sir! i learned a lot from your videos. we're hoping that you can make more vid from using chartJs, Js, Ajax in laravel. THank you so much!
{{ Form::submit('Submit', ['class' => 'btn btn-success']) }} {!! Form::close() !!} this was posted somewhere in the comments that fixed the problem for me.
If you use the new replacement for the Laravel Collective forms, you get all the same functionality but don't have to worry about spoofing these methods anymore. It supports PUT and DELETE straight out of the box now. :)
So the /postst/{id}/edit route is a default route when we do "php artisan make:controller PostsContoller --resource"? Because I was surprised it just worked like this.
Status Code: 405 Method Not Allowed message: "The PUT method is not supported for this route. Supported methods: GET, HEAD, POST." I kept getting this error so I removed the form hidden put but it worked just fine. Is this okay?
Anyone who gets '$post->title' and '$post->body' on the edit fields: edit.blade.php make sure to remove the ' ' on your $post->title and same goes to the body...
if you're receiving the error of Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException or just whenever you click the delete or edit button and it does not redirect you to another route then you can change the {!! Form::open(['action' => ['PostsController@update', $post->id], 'method'=> 'POST']) !!} to: {!!Form::model($post, array('method' => 'PUT', 'route' => array('posts.update', $post->id)))!!} also applies to the delete/destroy hope it helps
If you're following this tutorial at the time that i'm writting this, you may have an error when creating the form and passing the post's id, it will throw you a missing url parameters or something like that, to solve it you've to pass it in array form like this: {!! Form::open(array('action' => array('PostsController@update', $post->id), 'method'=>'POST')) !!}. You can check the documentation web page to see it: laravel.com/docs/4.2/html#opening-a-form
{!!Form::open(['action' => ['PostsController@destroy' , $post->id] , 'method' => 'DELETE' , 'class' => 'pull-right'])!!} {!!Form::open(['action' => ['PostsController@destroy' , $post->id] , 'method' => 'DELETE' , 'class' => 'pull-right'])!!} Specifying method in Form::open as a 'DELETE' or 'PUT' is much more logical i think. Specifying as a hidden field can be confusing
hi sir i like ur lectures sir in CRUD i have one doubt i face an error "undefined variable "id" while working with destroy method i copied similar to ur lecture pls reply for this
If you're gettin' "Uncaught TypeError: Cannot read property 'getEditor' of undefined at a (ckeditor.js:322) at Object.CKEDITOR.replace (ckeditor.js:326) at 6:75" error where something isn't defined, just put script tags with ckeditor in edit view and not in app layout. Undefined doesn't hurt in this case, but who knows further down the course what troubles can protrude from it.
help! the marker class in my show page after editing text will not display the highlighted marker....but it displays the marker on the edit page....can someone help? thanks
I had a question about adding scripts and php code into the blog body area. It looks like you can only add certain html tags, like , and a few more in the source code. Even if you add, images when you go to edit and save those elements disappear. Is it a CKeditor problem or a database filter problem? Any fix for this?
Thanks for this wonderful tutorial, you are a wonderful teacher. but i have a little problem on this part with the @foreach($posts as $post) am getingt undefined variable error. Please help me. "Undefined variable: posts (View: C:\wamp\www\myapp esources\views\dashboard.blade.php)"
Re posting this here from someone else lower on the comments, so that people can see it more easily. This piece of code should fix the problem when getting an error after editing a post. Edit Post {!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
Hi, regarding the notification of deletion of the post - mine does not show the bootstrap success notification (the green box above) upon redirecting to "/posts"; although the post is successfully removed. Tried if the pagination affects it but it doesn't.
I used 'method => PUT' @ 3:37 and works so didn't have to do the spoof request strategy. He said we cant use 'method=>PUT' but didn't really explain why. In fact this works for delete to so can just specify method as 'method' => 'DELETE' without doing the spoof request {{--{{Form::hidden('_method', 'DELETE')}}--}}. Perhaps this is ok with new laravel version.
How can I avoid "PostsControllers@store\PostsController@destroy not defined" without having to explicitly type the full path to the controller in "action" every time?
Once you get better, how you love to have full control over routes, Rails popularised the resource style of routes, how I hated it as routes and links got more inheritance, especially as sites got bigger. Also now I moved away from traditional routes, you know using the client instead of having the server do it, using mostly APIs now, loving the ability to use all the request verbs as-well. The very fact I can have just one endpoint in the server for every controller is wonderful, a large reason I moved away from resource style routes.
any one can solve this problum ?? htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp1\htdocs\lsappc esources\views\posts\edit.blade.php)
I create form::open with this format {!! Form::open(['method' => 'PUT', 'action' => ['App\Http\Controllers\Postscontroller@update', $posy->id] ])!!} And finally, it worked in my place.
Hi, I am getting this error when trying to submit an edited post: Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException I tried using the previous suggestions in the comments but they did not work for me. Used google as well and did not get through. If you can help, will appreciate it. Thank you.
I really don't see the point in spoofing the request and it seems I am not the only one. You should put an explanation somewhere. Could anyone explain it to me ?
So the point is HTML forms only allows you to use "GET" and "POST". However the route that ties to the update method in the post controller uses "PUT". You can't directly use "PUT" in the action attribute of the form tag. And if you leave it as POST and try to use it it will fail. Spoofing it is just a work around Laravel uses to get around this.
To elaborate on Broken Blade's response, a route for updating or deleting *could* be accessed via a POST request. However, for sake of syntactically meaningful code, it's best-practice to use PUT/PATCH and DELETE requests for routes that do those functions.
You can add alert first on your controller is like delete confirmation right ? , before the Update sistem code line. or you can use javascript / jQuery trigerring on delete button. you can use this code reference , laravel-tricks.com/tricks/confirmation-before-deleting-an-item
this codes works for me {!!Form::open(['action' => ['PostsController@destroy', $post->id], 'method' => 'POST','onsubmit' => 'return confirmDelete()'])!!} {{Form::hidden('_method', 'DELETE')}} {{Form::submit('Delete', ['class' => 'btn btn-danger'])}} {!!Form::close()!!} @endsection function confirmDelete() { var result = confirm('Are you sure you want to delete?'); if (result) { return true; } else { return false; } }
Loving course, however one problem. If i'm on create or edit page & choose to click 'BLOG' in navbar it cannot find the posts page. (Error:Trying to get property 'title' of non-object (View: C:\xampp\htdocs\lsapp esources\views\posts\show.blade.php). Don't understand why its looking for show.blade.php. The link works fine when moving along navbar but not from in or creating a post. Would be very grateful if anybody could point me to my error, many thanks
hey it says creating default object from empty value in edit.blade.php , can you please help ? $post = Post::find($id); // die(print_r($post)); $post->title = $request ->input('title'); //error from here $post->description = $request ->input('description'); die($post->title); $post->save();
Any had that this error and resolved it? Action App\Http\Controllers\PostsController@destroy not defined. (View: C:\xampp\htdocs\lsapp esources\views\posts\show.blade.php) Thanks.
How to fulfill edit function if form is dropdown list or datetime picker? Here are some of my code. Edit Tasks {!! Form::open(['action' => 'TasksController@store','method' => 'POST']) !!} {{Form::label('filetype','FileType')}} {{Form::select('filetype', array('pdf' => 'PDF', 'word' => 'Word','url' =>'URL',), 'pdf',['class'=>'form-control'])}} Please Select A Course Name @foreach($courses as $course) coursename == $course->id ? 'selected' : ''}}>{{ $course->coursename}} @endforeach
{{Form::label('taskduetime','Task Due Date')}} {{Form::date('taskduetime', \Carbon\Carbon::now(),['class'=>'form-control'])}}
if you're receiving the error of Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException or just whenever you click the delete or edit button and it does not redirect you to another route then you can change the {!! Form::open(['action' => ['PostsController@update', $post->id], 'method'=> 'POST']) !!} to: {!!Form::model($post, array('method' => 'PUT', 'route' => array('posts.update', $post->id)))!!} also applies to the delete/destroy hope it helps
after clicking on Delete button I am getting Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. can any one help me
u lost me at 'editor', i couldn't get that working, i tried to revert back to not use it but now as soon as i click on the text field in create post, it's submitting, i'll do it from scratch again
hello guys, anyone have an idea why this happens? after i edit the post. i look on the database and i have tag on the edited body post that i did. it look like this in the database: id: 2 title: Post Two body: This is post two created_at updated_at please help me with this.
if someone need this here is a tip: 'pull-right' it doesn't work with Bootstrap 4 so you want to use 'float-right'
thanks man
Thank you!
Thank you! it works.
hvala Mare
thanks man that was a pain in the a
PUT/DELETE are now allowed as form methods in Laravel v6.4.1:
and the routes work fine this way also.
in edit.blade.php
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
in show.blade.php
{!! Form::open(['action' => ['PostsController@destroy', $post->id], 'method' => 'DELETE']) !!}
hey bro..from Kenya here..you made me well conversant with Laravel,Thank you for the tutorial..Imma add myself to your subscribed users as a token of appreciation.
The Best Course ever for me, I traveled through UA-cam searching for Laravel Tuts, all i found are Hindi but also not suitable for me and too long, this one is the best !!!, thanks man
Hi Brad. I am from Pakistan..I got tears in my eyes dear when I gonna executes codes smoothly....I always pray for you brother...compact and reasonable series....thanks bro..Allah bless you always. Ameen
To keep the method even simpler, you could identify the post on the method construct.
instead of
public function destroy($id) {
}
you could use
public function destroy(Post $id) {
}
This replaces the $post = Post::find($id);
By the way, your tuts are awesome. Keep it up mate!
This is the part where it gets a little confusing for noobs like me. That being said, this series is pretty amazing. I think that your delivery is spot on. Thank you so much for sharing your time and knowledge with us. Much appreciated. Peter
Have to say this is the best Laravel series there is. And I have tried 2 series earlier to this and just left them in the middle because they were either boring or way to fast, to my liking.
For those using Bootstrap 4 it's float-right instead of pull-right.
This would be the full line of code:
{!!Form::open(['action' => ['App\Http\Controllers\PostsController@destroy', $post->id], 'method' => 'POST', 'class' => 'float-right'])!!}
StackOverFlow:
stackoverflow.com/questions/47121605/postscontrollerdestroy-not-defined-in-laravel/64236027#64236027
Thank You.
Brad,
God bless you ! These tutorials are super easy to understand and up to the topic ! loving this !
3:46
Using ck-editor form you actually can use 'method'=>' _PUT_ ' in place of 'method'=>' _POST_ ' instead of adding a __method_ hidden field. It will be automatically spoofed by sending a _method hidden field along with the submitted data.
thank you!
just wanna add that you can also do the same thing with delete
-c copies an entire line when nothing is selected (equal to yy in vi)
-v pastes the line again above the cursor (equal to p in vi)
-x deletes an entire line (equal to dd in vi)
those commands makes editing so much faster
btw... great videos
-x cuts the line, you'll be able to paste it after you -x, thanks for the helpful advice however, very useful.
Your videos are great no doubt and i love the way of how you explain things. It makes Laravel much more easier. Long Live Pal.
clean and simple as Laravel. Great tutorial. Thank you, Brad.
The code below works fine dont need to add that hidden form thng
Edit Post
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
{{ Form::label('title', 'Title', ) }}
{{ Form::text('title', $post->title, ['class' => 'form-control', 'placeholder' => 'Title']) }}
{{ Form::label('body', 'Body', ) }}
{{ Form::textarea('body', $post->body, ['class' => 'form-control', 'placeholder' => 'Body', 'id' => 'article-ckeditor', 'style' => 'resize:none;']) }}
{{ Form::submit('Submit', ['class' => 'btn btn-success']) }}
{!! Form::close() !!}
Thanks 😊 bro ......👍👍
what is the different btw?
@@duckyeah896 PostsController@update
You can use new Laravel directives to generate the _method input, like this
@method('PUT')
@csrf
@csrf
@method('PUT')
Thanks a lot!
I know this is old, but if you're like me you can't stand that the application redirects to the post list after creating and updating posts. If you're in the same boat, update your return line in the store method in PostsController.php to:
return redirect()->route('posts.show', ['post' => $post->id])->with('success', 'Post created!');
and also update your return line in the update method to:
return redirect()->route('posts.show', ['post' => $id])->with('success', 'Post updated!');
I don't think that would work... If you want to have your application redirects to the newly created post, just add the id from the Post object to the URL:
return redirect('/posts/'.$post->id)->with('success', 'Post Created');
And if you want to do the same thing with the Update controller:
return redirect('/posts/'.$post->id)->with('success', 'Post Updated');
They are both working anyways.
@@sasajovicic2384 what you think is irrelevant. If you want to be helpful then test it and THEN see if it works or not. Because in this case it works just fine and is actually the recommended way of doing this (see laravel documentation)
It's works very well. Thanks in advanced but I had one question, why I can't use this way 'posts/show'? because I get an error when used this way. I must used this way 'posts.show' and no errors.
Nice man but I only used this on edit method
In laravel 6 Laravel Collective, you can directly use
{!! Form::open(['method' => 'PUT', 'action' => ['PostsController@update', $post->id] ]) !!}
PUT and DELETE methods will now be spoofed automatically
how you got html forms working on laravel 6?
@@mrbale1815 just put the tags on the blade. And if u want to retain the value then use value="{{ old(name) }}"
Excellent, thank you
if you are getting The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. then all you can do is
{!!Form::hidden('_method','PUT')!!}
use this instead of
{{Form::hidden('_method','PUT')}}
.
the first one works well
if someone has problem with the form 'action' and it doesn't work, you should use 'url' instead of action.
THANK YOU!
in version 5.8
{{FORM::hidden('_method','xxxx')}} is no need to use anymore
Another great one. You need to have a tv show for nerds. love it.
great series sir! i learned a lot from your videos. we're hoping that you can make more vid from using chartJs, Js, Ajax in laravel. THank you so much!
Very helpful. Thank you. I've spent all morning looking for a way to do this!
The class 'pull-right' has been replaced by 'float-right'.So must change in order to obtain same as: "7:25 in video"
i just want to say thanks man. it really works all your tutorial for me.
I'm soooo in love of this tutorial, amazing explanation Brad..thank u bro
Yes indeed. It's amazing!
Undefined variable: post (View: C:\xampp\htdocs\lsapp
esources\views\posts\show.blade.php) get this after edit post
Edit Post
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
{{ Form::label('title', 'Title', ) }}
{{ Form::text('title', $post->title, ['class' => 'form-control', 'placeholder' => 'Title']) }}
{{ Form::label('body', 'Body', ) }}
{{ Form::textarea('body', $post->body, ['class' => 'form-control', 'placeholder' => 'Body', 'id' => 'article-ckeditor', 'style' => 'resize:none;']) }}
{{ Form::submit('Submit', ['class' => 'btn btn-success']) }}
{!! Form::close() !!}
this was posted somewhere in the comments that fixed the problem for me.
@@168severi Do laravel collective forms still work? Finding these lectures difficult because laravelcollective website is down.
@@julianlaci5421 i dont think they do, you need to work around them and look around a bit sadly when following these
For those :: pull-right doesn't work USE THIS CODE
Edit
{!!Form::open(['action' => ['PostsController@destroy', $post->id, 'method' => 'POST', 'class' => 'float-right']])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger float-right'])}}
{!!Form::close()!!}
THANK YOU!
bro your are love you made this so simple i have been able to create live football matches fixtures website watching your videos
Thanks man
4 more to go. Easy to follow. :) .
Your videos are insane! Keep it up
Nice! But i have a question. Why is there a Form:hidden() method. I did not understand. Thanks for explanation!
The html form tag has only 'GET' or 'POST' these two method.
stackoverflow.com/questions/8054165/using-put-method-in-html-form
If you use the new replacement for the Laravel Collective forms, you get all the same functionality but don't have to worry about spoofing these methods anymore. It supports PUT and DELETE straight out of the box now. :)
edit page doesn't seem to open.. hmmm, trying to debug and find how to fix it.
Great video, thanks.
So the /postst/{id}/edit route is a default route when we do "php artisan make:controller PostsContoller --resource"? Because I was surprised it just worked like this.
Awesome tutorial!
Thank you my friend!
Status Code: 405 Method Not Allowed message: "The PUT method is not supported for this route. Supported methods: GET, HEAD, POST."
I kept getting this error so I removed the form hidden put but it worked just fine. Is this okay?
if it works, it works
Very nice tutorial. Easy to follow. Keep it up :)
Now in Laravel 8 we do not need to use the hidden method for put & delete we can use it directly
excellent work
Anyone who gets '$post->title' and '$post->body' on the edit fields:
edit.blade.php
make sure to remove the ' ' on your $post->title and same goes to the body...
why?
Thanks very much, surprised more people didn't have this issue
Awesome videos!!
if you're receiving the error of Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException or just whenever you click the delete or edit button and it does not redirect you to another route then you can change the
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method'=> 'POST']) !!}
to:
{!!Form::model($post, array('method' => 'PUT', 'route' => array('posts.update', $post->id)))!!}
also applies to the delete/destroy
hope it helps
Thank you so much, the previous method with form was working and then after a update nothing, anywho your solution worked perfect thanks
great video, i learned a lot from you. thanks much.
Is "spoofing" the best thing to do?
If you're following this tutorial at the time that i'm writting this, you may have an error when creating the form and passing the post's id, it will throw you a missing url parameters or something like that, to solve it you've to pass it in array form like this: {!! Form::open(array('action' => array('PostsController@update', $post->id), 'method'=>'POST')) !!}.
You can check the documentation web page to see it: laravel.com/docs/4.2/html#opening-a-form
I want to display old value when updating,how?
{!!Form::open(['action' => ['PostsController@destroy' , $post->id] , 'method' => 'DELETE' , 'class' => 'pull-right'])!!}
{!!Form::open(['action' => ['PostsController@destroy' , $post->id] , 'method' => 'DELETE' , 'class' => 'pull-right'])!!}
Specifying method in Form::open as a 'DELETE' or 'PUT' is much more logical i think. Specifying as a hidden field can be confusing
hi sir i like ur lectures
sir in CRUD i have one doubt
i face an error "undefined variable "id" while working with destroy method
i copied similar to ur lecture
pls reply for this
i am having the same error !! have you fixed it?
Please help...,
"Class 'Collective\Html\HtmlServiceProvider' not found"
If you're gettin' "Uncaught TypeError: Cannot read property 'getEditor' of undefined
at a (ckeditor.js:322)
at Object.CKEDITOR.replace (ckeditor.js:326)
at 6:75" error where something isn't defined, just put script tags with ckeditor in edit view and not in app layout. Undefined doesn't hurt in this case, but who knows further down the course what troubles can protrude from it.
help! the marker class in my show page after editing text will not display the highlighted marker....but it displays the marker on the edit page....can someone help? thanks
Amazing videos :)
Thanks
I had a question about adding scripts and php code into the blog body area. It looks like you can only add certain html tags, like , and a few more in the source code. Even if you add, images when you go to edit and save those elements disappear. Is it a CKeditor problem or a database filter problem? Any fix for this?
How can I display errors (stack trace) like in the video? 8:37
I have Laravel 5.6.23
Thanks for this wonderful tutorial, you are a wonderful teacher. but i have a little problem on this part with the @foreach($posts as $post) am getingt undefined variable error. Please help me. "Undefined variable: posts (View: C:\wamp\www\myapp
esources\views\dashboard.blade.php)"
Re posting this here from someone else lower on the comments, so that people can see it more easily. This piece of code should fix the problem when getting an error after editing a post.
Edit Post
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
{{ Form::label('title', 'Title', ) }}
{{ Form::text('title', $post->title, ['class' => 'form-control', 'placeholder' => 'Title']) }}
{{ Form::label('body', 'Body', ) }}
{{ Form::textarea('body', $post->body, ['class' => 'form-control', 'placeholder' => 'Body', 'id' => 'article-ckeditor', 'style' => 'resize:none;']) }}
{{ Form::submit('Submit', ['class' => 'btn btn-success']) }}
{!! Form::close() !!}
Strange enough, the hidden input to spoof a PUT request is no longer required this way. thanks man!
Hi, regarding the notification of deletion of the post - mine does not show the bootstrap success notification (the green box above) upon redirecting to "/posts"; although the post is successfully removed. Tried if the pagination affects it but it doesn't.
You could have used Form::model instead of Form::open in the edit template
im curious, why form::model?
Can we do it without using resource in the route. ?? Custom edit and update without using the custom resource controller.
I used 'method => PUT' @ 3:37 and works so didn't have to do the spoof request strategy. He said we cant use 'method=>PUT' but didn't really explain why. In fact this works for delete to so can just specify method as 'method' => 'DELETE' without doing the spoof request {{--{{Form::hidden('_method', 'DELETE')}}--}}. Perhaps this is ok with new laravel version.
thanks bud
How can I avoid "PostsControllers@store\PostsController@destroy not defined" without having to explicitly type the full path to the controller in "action" every time?
Is it necessary to use form helper in blade?
Can't we just write html for it?
Is there a reason why you aren't using the built in route function? Your links are hard coded which is yukky. :(
Once you get better, how you love to have full control over routes, Rails popularised the resource style of routes, how I hated it as routes and links got more inheritance, especially as sites got bigger.
Also now I moved away from traditional routes, you know using the client instead of having the server do it, using mostly APIs now, loving the ability to use all the request verbs as-well.
The very fact I can have just one endpoint in the server for every controller is wonderful, a large reason I moved away from resource style routes.
bro how to update image
Hey, how do I put it using regular forms?
I have problem with 'edit' part. I put values in form but it doesn't show proper values. It show values from just one user. Why?
Hey 2020(under ecq) guys, 'PostsController@update'
what?
@@alfahami5210 Same lmao
k very usefull tutorial but how about just need to link two different sites like wordpress and prestashop whit laravell ?
in post->id id is not taking , instead of id it is displaying only character id not showing number. what to do ???
I have errors. Trying to get property of non-object (View: C:\laragon\www\unorfiles
esources\views\posts\edit.blade.php)
any one can solve this problum ??
htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp1\htdocs\lsappc
esources\views\posts\edit.blade.php)
I create form::open with this format
{!! Form::open(['method' => 'PUT', 'action' => ['App\Http\Controllers\Postscontroller@update', $posy->id] ])!!}
And finally, it worked in my place.
for some reason when i add that delete form to the show page it breaks the app, i'm getting a 500 error back.
Hi, I am getting this error when trying to submit an edited post:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
I tried using the previous suggestions in the comments but they did not work for me. Used google as well and did not get through. If you can help, will appreciate it.
Thank you.
I really don't see the point in spoofing the request and it seems I am not the only one. You should put an explanation somewhere. Could anyone explain it to me ?
So the point is HTML forms only allows you to use "GET" and "POST". However the route that ties to the update method in the post controller uses "PUT".
You can't directly use "PUT" in the action attribute of the form tag. And if you leave it as POST and try to use it it will fail. Spoofing it is just a work around Laravel uses to get around this.
To elaborate on Broken Blade's response, a route for updating or deleting *could* be accessed via a POST request. However, for sake of syntactically meaningful code, it's best-practice to use PUT/PATCH and DELETE requests for routes that do those functions.
how can i get an alert msg before delete? tnx :)
You can add alert first on your controller is like delete confirmation right ? , before the Update sistem code line. or you can use javascript / jQuery trigerring on delete button. you can use this code reference , laravel-tricks.com/tricks/confirmation-before-deleting-an-item
this codes works for me
{!!Form::open(['action' => ['PostsController@destroy', $post->id], 'method' => 'POST','onsubmit' => 'return confirmDelete()'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
@endsection
function confirmDelete() {
var result = confirm('Are you sure you want to delete?');
if (result) {
return true;
} else {
return false;
}
}
tnx seems good for me also )
Thanks a lot :) , works great for me either.
this helped me. thank you so much
Undefined offset: 0 (View: /Applications/XAMPP/xamppfiles/htdocs/laravel/resources/views/posts/show.blade.php)
Why do you use links instead of buttons?
Loving course, however one problem. If i'm on create or edit page & choose to click 'BLOG' in navbar it cannot find the posts page. (Error:Trying to get property 'title' of non-object (View: C:\xampp\htdocs\lsapp
esources\views\posts\show.blade.php). Don't understand why its looking for show.blade.php. The link works fine when moving along navbar but not from in or creating a post. Would be very grateful if anybody could point me to my error, many thanks
hey it says creating default object from empty value in edit.blade.php , can you please help ?
$post = Post::find($id);
// die(print_r($post));
$post->title = $request ->input('title'); //error from here
$post->description = $request ->input('description');
die($post->title);
$post->save();
its say undefined variable id
it says trying to get id of non object , can you please help ? in edit.blade.php
btn-default actually not existed during my time of trying, I've check my css file (\lsapp\public\css\app.css), btn-default is not found
I've used .btn-outline-secondary instead but pls suggest any alternative way to get btn-default
when i do php artisan route:list i get this 'Target class [PostsController] does not exist.'
Hello! Can someone please help me? It seems like the files are not getting "updated" nor can the files be deleted. How do I fix this? Please advise!
i am using the destroy function to delete as in the video but it goes to store function when i press the delete button
check if your form action in show.blade.php is modified from store to destroy, should be ('PostsController@destroy')
Any had that this error and resolved it? Action App\Http\Controllers\PostsController@destroy not defined. (View: C:\xampp\htdocs\lsapp
esources\views\posts\show.blade.php) Thanks.
I got this same error, was it resolved?
hi did u resolve this error?
How to fulfill edit function if form is dropdown list or datetime picker?
Here are some of my code.
Edit Tasks
{!! Form::open(['action' => 'TasksController@store','method' => 'POST']) !!}
{{Form::label('filetype','FileType')}}
{{Form::select('filetype', array('pdf' => 'PDF', 'word' => 'Word','url' =>'URL',), 'pdf',['class'=>'form-control'])}}
Please Select A
Course Name
@foreach($courses as $course)
coursename == $course->id ? 'selected' : ''}}>{{ $course->coursename}}
@endforeach
{{Form::label('taskduetime','Task Due Date')}}
{{Form::date('taskduetime', \Carbon\Carbon::now(),['class'=>'form-control'])}}
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
how to solve this?
if you're receiving the error of Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException or just whenever you click the delete or edit button and it does not redirect you to another route then you can change the
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method'=> 'POST']) !!}
to:
{!!Form::model($post, array('method' => 'PUT', 'route' => array('posts.update', $post->id)))!!}
also applies to the delete/destroy
hope it helps
I am still getting the error, is there any other way around it?
No, the problem is your DELETE function. Don't forget to use the underscore with the method. Example '_method'.
@@hillaryyambao156 thank you!
@@mikekyto thanks a lot!
i cant dellte file they said
Call to a member function delete() on null
Check your action routing maybe you are not getting the id coz your getting null which means nothing to delete.
Downloaded you source code but its ending up with fatal error require(). Do you have any blog where i can solve my problem ?
Shouldn't it be request?
after clicking on Delete button I am getting Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE.
can any one help me
u lost me at 'editor', i couldn't get that working, i tried to revert back to not use it but now as soon as i click on the text field in create post, it's submitting, i'll do it from scratch again
My success message is not being shown. Please help!!
Does CKeditor work in laravel 7.9. I tried several times installing with no luck
Try tinymce. You can self host it for free and it is open source. Wordpress uses it too
How can i put confirmation on delete button?
use my code
show.blade.php
@extends('layout.app')
@section('content')
Back
{{$post->title}}
{!!$post->body!!}
Ditulis pada {{$post->created_at}}
Edit
function ConfirmDelete()
{
var x = confirm("Are you sure you want to delete?");
if (x)
return true;
else
return false;
}
{!! Form::open(['action' => ['PostsController@destroy', $post->id], 'method' => 'POST', 'class' => 'float-right', 'onsubmit' => 'return ConfirmDelete()']) !!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
@endsection
If I want to removed confirmation , How can I do?
use my code
show.blade.php
@extends('layout.app')
@section('content')
Back
{{$post->title}}
{!!$post->body!!}
Ditulis pada {{$post->created_at}}
Edit
function ConfirmDelete()
{
var x = confirm("Are you sure you want to delete?");
if (x)
return true;
else
return false;
}
{!! Form::open(['action' => ['PostsController@destroy', $post->id], 'method' => 'POST', 'class' => 'float-right', 'onsubmit' => 'return ConfirmDelete()']) !!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
@endsection
hello guys, anyone have an idea why this happens?
after i edit the post. i look on the database and i have tag on the edited body post that i did.
it look like this in the database:
id: 2
title: Post Two
body: This is post two
created_at
updated_at
please help me with this.
if a remove ckeditor scripts. when i edit the post it is doing fine.