Laravel From Scratch [Part 8] - Edit & Delete Data

Laravel From Scratch [Part 8] - Edit & Delete Data

Traversy Media

7 лет назад

231,138 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Fadwa40
@Fadwa40 - 06.07.2023 12:13

k very usefull tutorial but how about just need to link two different sites like wordpress and prestashop whit laravell ?

Ответить
@larrycoleman9513
@larrycoleman9513 - 05.05.2022 02:25

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 <p>, <h2> 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?

Ответить
@nikaa9956
@nikaa9956 - 23.02.2022 17:30

I want edit button I have edit.blade.php and index.blade.php but when I clicked on Edit I get 404
NOT FOUND. Please someone do not know what with it ?

Ответить
@Norvilt
@Norvilt - 12.01.2022 19:09

Hey, how do I put it using regular forms?

Ответить
@manitalari8013
@manitalari8013 - 23.06.2021 12:26

hi guys ,,any body can help i am getting error ErrorException
Trying to get property 'title' of non-object (View: C:\Users\DELL\xampp\htdocs\example-app\resources\views\pages\show.blade.php)

Ответить
@korokoV23
@korokoV23 - 12.06.2021 03:04

Now in Laravel 8 we do not need to use the hidden method for put & delete we can use it directly

Ответить
@MaishYeol
@MaishYeol - 03.05.2021 02:54

when i do php artisan route:list i get this 'Target class [PostsController] does not exist.'

Ответить
@HashimAziz1
@HashimAziz1 - 22.03.2021 00:50

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?

Ответить
@pichmongkol168
@pichmongkol168 - 11.03.2021 12:20

Great video, thanks.

Ответить
@Dominiclee12
@Dominiclee12 - 28.11.2020 08:15

If I have a radio button input, how should I write the code to check the current value? For example, if it's a gender radio input and the current post is male and I want it to be checked while editing the post.

Ответить
@w3healthdose
@w3healthdose - 11.11.2020 11:48

hello guys, anyone have an idea why this happens?
after i edit the post. i look on the database and i have <p> tag on the edited body post that i did.
it look like this in the database:
id: 2
title: Post Two
body: <p>This is post <strong><em>two</em></strong>
created_at
updated_at
please help me with this.

Ответить
@Npb10
@Npb10 - 28.07.2020 13:47

Thank you my friend!

Ответить
@RamadhaniShemahonge
@RamadhaniShemahonge - 06.05.2020 11:17

Does CKeditor work in laravel 7.9. I tried several times installing with no luck

Ответить
@j4878
@j4878 - 23.04.2020 16:20

Hey 2020(under ecq) guys, 'PostsController@update'

Ответить
@sangeeth810
@sangeeth810 - 13.04.2020 17:39

excellent work

Ответить
@ismaila2790
@ismaila2790 - 01.04.2020 03:41

Problems i encountered:
1.I couldn't set the TextArea value.
2.After I click edit an error popped up:
"The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE."

Solution:

<form action="{{ route('posts.update', $post->id) }}" method="POST">
<div class="form-group">
<label for="Title">Title</label>
<input type="text" class="form-control" name="title" value="{{$post->title}}" placeholder="Title">
</div>



<div class="form-group">
<label for="Body">Body</label>

<textarea class="form-control" name="body" value="jjjj" rows="3" placeholder="Body text">
{{-- Problem 1 Solution-start --}}
{!!$post->body!!}
{{-- Problem 1 Solution-end --}}
</textarea>
</div>


<div class="form-group">
{{-- Problem 2 Solution-start --}}
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
{{-- Problem 2 Solution-end --}}


<input type="submit" value="Submit" class="btn-outline-secondary btn ">
</div>
</form>

Ответить
@atmarmomand6334
@atmarmomand6334 - 31.03.2020 17:13

any one can solve this problum ??
htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp1\htdocs\lsappc\resources\views\posts\edit.blade.php)

Ответить
@quantumcd1045
@quantumcd1045 - 16.03.2020 18:48

for some reason when i add that delete form to the show page it breaks the app, i'm getting a 500 error back.

Ответить
@manthrarasstogi378
@manthrarasstogi378 - 11.03.2020 13:40

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

Ответить
@cecironalejoiii7680
@cecironalejoiii7680 - 16.02.2020 06:51

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

Ответить
@karlomiguelperez4450
@karlomiguelperez4450 - 12.02.2020 06:19

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.

Ответить
@RIMJANESSOHMALOOG
@RIMJANESSOHMALOOG - 07.02.2020 17:14

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

Ответить
@vikastomar7206
@vikastomar7206 - 05.02.2020 08:19

bro how to update image

Ответить
@MustafaBirsoz
@MustafaBirsoz - 28.01.2020 18:35

Thanks man

Ответить
@mohammedrayyan3029
@mohammedrayyan3029 - 20.11.2019 11:36

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

Ответить
@rexparker6011
@rexparker6011 - 04.11.2019 04:36

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']) !!}

Ответить
@veenadanak559
@veenadanak559 - 29.10.2019 15:06

Is it necessary to use form helper in blade?
Can't we just write html for it?

Ответить
@goldensparrowmobile9924
@goldensparrowmobile9924 - 26.10.2019 16:01

anyone can help me about this

Ответить
@goldensparrowmobile9924
@goldensparrowmobile9924 - 26.10.2019 15:59

Undefined offset: 0 (View: /Applications/XAMPP/xamppfiles/htdocs/laravel/resources/views/posts/show.blade.php)

Ответить
@goldensparrowmobile9924
@goldensparrowmobile9924 - 26.10.2019 15:59

i got this error 👆

Ответить
@gcooper642
@gcooper642 - 05.09.2019 13:23

Very helpful. Thank you. I've spent all morning looking for a way to do this!

Ответить
@janinesantos7115
@janinesantos7115 - 26.08.2019 17:14

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?

Ответить
@blank001
@blank001 - 19.08.2019 20:53

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.

Ответить
@lizempson2916
@lizempson2916 - 17.08.2019 14:57

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\resources\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

Ответить
@user-tc3sh9pl4e
@user-tc3sh9pl4e - 15.08.2019 04:00

clean and simple as Laravel. Great tutorial. Thank you, Brad.

Ответить
@shaneabutan6158
@shaneabutan6158 - 27.07.2019 03:42

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...

Ответить
@esraasalah8012
@esraasalah8012 - 26.07.2019 12:34

I'm soooo in love of this tutorial, amazing explanation Brad..thank u bro

Ответить
@elliotching1142
@elliotching1142 - 07.07.2019 08:34

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

Ответить
@bohem7298
@bohem7298 - 31.05.2019 12:25

in version 5.8
{{FORM::hidden('_method','xxxx')}} is no need to use anymore

Ответить
@pooriam2628
@pooriam2628 - 23.05.2019 12:32

if someone has problem with the form 'action' and it doesn't work, you should use 'url' instead of action.

Ответить
@168severi
@168severi - 21.05.2019 10:51

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.
<h1>Edit Post</h1>
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
<div class="form-group">
{{ Form::label('title', 'Title', ) }}
{{ Form::text('title', $post->title, ['class' => 'form-control', 'placeholder' => 'Title']) }}
</div>
<div class="form-group">
{{ Form::label('body', 'Body', ) }}
{{ Form::textarea('body', $post->body, ['class' => 'form-control', 'placeholder' => 'Body', 'id' => 'article-ckeditor', 'style' => 'resize:none;']) }}
</div>
{{ Form::submit('Submit', ['class' => 'btn btn-success']) }}
{!! Form::close() !!}

Ответить
@kamaldeepak418
@kamaldeepak418 - 15.05.2019 09:40

Undefined variable: post (View: C:\xampp\htdocs\lsapp\resources\views\posts\show.blade.php) get this after edit post

Ответить
@abdullahshoaib7377
@abdullahshoaib7377 - 05.05.2019 12:45

i am using the destroy function to delete as in the video but it goes to store function when i press the delete button

Ответить
@djsamke384
@djsamke384 - 29.04.2019 21:12

The code below works fine dont need to add that hidden form thng


<h1>Edit Post</h1>
{!! Form::open(['action' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
<div class="form-group">
{{ Form::label('title', 'Title', ) }}
{{ Form::text('title', $post->title, ['class' => 'form-control', 'placeholder' => 'Title']) }}
</div>
<div class="form-group">
{{ Form::label('body', 'Body', ) }}
{{ Form::textarea('body', $post->body, ['class' => 'form-control', 'placeholder' => 'Body', 'id' => 'article-ckeditor', 'style' => 'resize:none;']) }}
</div>
{{ Form::submit('Submit', ['class' => 'btn btn-success']) }}
{!! Form::close() !!}

Ответить
@karthikr5033
@karthikr5033 - 29.04.2019 09:29

in post->id id is not taking , instead of id it is displaying only character id not showing number. what to do ???

Ответить