Laravel 5.2 PHP Build a social network - Deleting Posts
HTML-код
- Опубликовано: 29 сен 2024
- Build a complete Social Network Web Application with PHP Laravel. In this video we will take care about deleting posts.
Complete source code: github.com/msc...
Complete Laravel-course on Udemy: www.udemy.com/... (Coupon: RUclips1)
In this course we'll build a neat little social network and cover the basics of developing with Laravel.
You can follow me on Twitter (@maxedapps), Facebook ( / academindchannel ) or visit our Website (www.academind.com).
See you in the videos!
Hi,I have watched all this playlist videos of creating a social network with Laravel!
I am really enjoying this tutorials, and I am codding this project at the same time.
Keep with the good work, it's really helpfull, I am now waiting for the next videos in order to continue the project.
Thanks for your videos!
+Micro7HD
Hi, it's great to hear that you like my content! Thank you!
I created another page which can be accessed without logging in, but when i try to access it it says:
Undefined variable: posts (View: C:\wamp64\www\ProjectName
esources\views\PageName.blade.php)
I asked the full question in stackoverflow and woul rly appreciate if anybody could help.
stackoverflow.com/questions/41695880/laravel-trying-to-output-posts-but-controller-function-seem-to-work-wrong
You are some legend ,thank you so much !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:) :)
So happy to read that artur! YOU and all the others supporting that channel in such an awesome way are legends :)
i love you holy shit
Hi, i wonder how does deployment goes to actual server? in java app we just export our project as project.war file and just place the file in httpdoc folder restart the server and we are done and if its a springs+hibernate project our database tables are automatically created and ready to use! is that the same case with laravel framework too? or do we have too install laravel CLI on server to and run migrate command manually to create our tables? Thank You :)
+JS Ever
My deployment process looks like that, yes.
Ship the files and run all migrations via artisan command line.
+Mindspace that means i need to install composer CLI on server? what if my server doesn't have composer installed? is there an alternative to get that databse generated?
No you don't need composer there at all. Artisan is run via PHP (therefore we use it with 'php artisan...'). So no need for composer
+Mindspace Great i got it. Thanks a lot :)
Successfully Deleted , Thank You Respected Sir
Fantastic job. Perfect pacing for following along to recreate what you are doing. Great explanations. Thank you for posting this!
+Ncojay
Really awesome to read this, thanks a lot!
Your tutorials are great! Thanks a lot :)
But am getting an error.. After logging out, am unable to sign in.
route page code:
//SignIn
Route::post('/signin',[
'uses'=>'UserController@postSignIn',
'as' =>'signin'
]);
//Dashboard
Route::get('/dashboard',[
'uses'=>'PostController@getDashboard',
'as' =>'dashboard'
]);
//Logout
Route::get('/logout',[
'uses'=>'UserController@getLogout',
'as' =>'logout'
]);
Trying to get property of non-object (View: C:\xampp\htdocs\social_site
esources\views\dashboard.blade.php)
@foreach($posts as $post)
{{ $post->body }}
Posted By {{$post->user->first_name}} on {{$post->created_at}}
Like |
Dislike |
Edit |
Delete
@endforeach
Can you help me out?? Am badly stucked :(
waiting for your reply.. Thanks
Hi, Thanks for the great tutorial and btw i don't know why i get an error
ErrorException in UrlGenerator.php line 307:
Route [post.delete] not defined. (View: C:\xampp\htdocs\www\devrk_laravel
esources\views\dashboard.blade.php)
InvalidArgumentException in UrlGenerator.php line 307:
Route [post.delete] not defined.
Here's my PostController.php
public function getDeletePost($post_id)
{
$post = Post::where('id', $post_id)->first();
$post->delete();
return redirect()->route('dashboard')->with(['message' => 'Successfully deleted']);
}
and this is my routes.php
Route::get('/delete-post/{post_id}', [
'uses' => 'PostController@getDeletePost',
'name' => 'post.delete',
'middleware' => 'auth'
]);
and this is the dashboard.blade.php
@foreach($posts as $post)
{{ $post->body }}
Posted by {{ $post->user->first_name }} on {{$post->created_at}}
Like |
Dislike |
Edit |
Delete
@endforeach
i've already check the codes 3rd time i even play back the video again again i didn't find what's wrong.
btw im using the latest laravel 5.2 ? because i just installed it yesterday.
God bless and more power.
+Devrk ai
Hi, I'm happy to hear that you are liking my videos! :)
You have a little but important error in your routes.php file. Routes are named via the 'as' key, not 'name'.
It should work once you change the route to look like this:
Route::get('/delete-post/{post_id}', [
'uses' => 'PostController@getDeletePost',
'as' => 'post.delete',
'middleware' => 'auth'
]);
+Mindspace Wow srsly how dumm am i HAHA! why the heck i was using name on that o.O maybe i just got so tired haha thank you so much +Minspace
Tiny things like these happen all the time...the worst thing is, that such errors take the longest to spot. ;)
Hi +Mindspace, Thankyou for super great tutorials, I'm an absolute beginner to PHP MVC and your videos are helping me a lot. Just a quick question here, in route:
Route::get('/deletepost/{post_id}',[
'uses'=>'PostController@getDeletePost',
'as'=>'post.delete',
'middleware'=>['auth']
]);
why do we have to pass {post_id} specifically in /deletepost/{post_id}? if I remove {post_id} its anyways going to redirect on /deletepost?post_id={id}. And in this case controller is giving me error "missing argument 1"
Any way to pass the argument without specifying /deletepost/{post_id} in route?
Hi first i'd like to thank you for the great job you are doing in here Thank you so much
i've a question about the laravel framework or frameworks in general now im at the video #11 and i've understood almost all the features that you were talking about
but the question that i want to ask is that we've studied many things in php such as how to write some SQL queries to connect into the DATABASE and to insert/update/delete posts and also how to rewrite our URLs using pure php code
And now by using laravel everything is much simpler an faster so after mastering these powerful tools provided by laravel we will be able to do great things but the problem in other side we will forget the pure PHP codes that we were writing before
So is it the case for all developers or i'm just seeing it from the wrong side?
Thank you in advance
Question: Why did you use a GET HTTP verb instead of DELETE? Doesn't using a delete route make more sense?
You can't send DELETE requests by submitting a HTML form. (sidenote: you can with some tricks)
When do DELETE, PUT, PATCH, and others apply to web programming then? Are they just API requests?
Yes, you can use them when sending Ajax requests.
Ah, thank you. Really appreciate your help sir.
Laravel and admin lte crud plz
Is not safe with get method to delete something. It can be hacked easily. Is not best practice.
This man is a genius, stop pretending that you know more than him (jk lol, but he is a genius)
Wouldn't be better to just change for example delete = 1 in database for history purposes? Btw 😁 excellent tutorials man!
+Johny Manuelli
Hi Johny,
that's a valid point you're bringing up here. It really depends on the application, but of course this certainly is a better way of keeping the history/ backups is important.
Under other circumstances this might not be needed. Very good suggestions though and definitely which you'll implement in such a way a lot.
+Johny Manuelli Laravel has SoftDeletes , check the documentation here : laravel.com/docs/5.2/eloquent#soft-deleting
great great great job !!!!!! thank you so much ...........
Thanks so much Pravesh, really happy to read that you liked the video!
One question: where is it specified which table the function shall fetch the data from?
Laravel assumes a certain table naming. If your Model is named "User", then it assumes the table to be named "users" (lowercase, plural).
+Mindspace That is very nice indeed. I knew that this framework does most of the heavy lifting, but assumption of names, that is new level of awesome. And again, great tutorials mate, keep up the good work!
Thank you, I'll do my best! :)
Thanks you !!!
Thanks a lot for your comment Cheikh!
I'm watching series and it's really cool, you explain very well