Laravel 5.2 PHP Build a social network - Likes & Dislikes (1/3 - Models & AJAX)
HTML-код
- Опубликовано: 16 мар 2016
- Build a complete Social Network Web Application with PHP Laravel. This videos shows to start with the implementation of a Like/Dislike mechanic by setting up the backend and configuring the AJAX call.
Complete source code: github.com/mschwarzmueller/la...
Complete Laravel-course on Udemy: www.udemy.com/modern-web-deve... (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! Наука
This is OVER THE TOP!
Fantastic job! Love the greenscreen overlay - being able to see a person talk when they talk for a while really helps keep the focus!.
+Jack Fruh
Hi Jack, I'm very happy you're liking the format. I also helps me to explain things better and it feels more like actually talking to someone than just talking to the laptop ;)
Great video as always. You are the best laravel teacher on the internet hands down.
Wow, amazing to hear this, many, many thanks! :)
I'm very Thankful for your explanations, keep doing it and i will allways appreciate the help. Thank you dude.
+Pedro Lugo
Thank you Pedro, I'll certainly keep the videos coming! :)
I like your teaching style based on a story of every single detail. Keep going on. Regards
Great job!
thank you very much :)
Haven't worked ahead too much in the like videos, just wanted to say that I chose to make the tags in the dashboard view "like" and "dislike". This way, if I happen to want to modify the the code or put the "like" and "dislike" buttons in a different place, it will be more dynamic than hardcoding them to recognize if it the first element in the list, like he did in this video.
Personal preference, but I prefer to take the extra steps to make things dynamic to save the possibility of extra work (or confusion of why you broke something) down the line.
thank you! It's easy learning this from you XD
+Sheila Clitar
Great to hear that! :)
I'd say it's preferrable not to rely on the DOM structure too much IRL because it can change quite a bit as an application evolves over time. For identifying the like/dislike links, using a data attribute for example would be more robust.
Дуже дякую !!
thank you :D
+Aya Ayari
Happy to see you're liking it! :)
Hi Max, if i want to make a save button for save the post the user interesting in, I think I can apply the similar method as the likes and Dislikes. But the save function should only have one button how to code my Ajax??
+Rebecca Lau
Hi Rebecca, I'm not sure if I understand you correctly. The AJAX request would probably send the post_id to the server and it would of course be triggered upon button hit.
How can we have up voting and down voting system using laravel
Hey, which was the text editor you were using?
It's PHPStorm in this video
Academind, thank you for the info
Would it be possible to somehow store session info (or something) instead of user_id ? This to enable anyone to "heart" an article, comment, etc. but in the same time disable him to mess up with the button clicking it randomly over and over again ... at least while in the same session.
You mean store session id in the database? I would rather simply implement a check based on the fact if the userlikepost connection already exists. That would also prevent multiple likes.
I've sent you an email about the whole problem so if you have time, it would be great if you check it out. :)
I have problems with getting postId cause it's from the edit video & i didn't watch it
thank you for the tutorial. and are you sick?
+mehdi lamaafar
Yes, during the recoding of this video I was sick. I tried to cut out all sniffing etc. but I apologize if it's still hearable.
Why would you do these foreign-key relations in code? Why not use Workbench?
I still dont understand what excatly we r doing in these Like.php User.php and Post.php .
I understand It a bit but a little explanation would rly help me out.
Hey man, i did like and dislike button, when a user press one of them, i then call js function, that function will communicate with my php file using ajax, then i update a table where i store Likes and dislike counts; in your php you have to check if its a duplicate or new like or dislike, after you update the table, then reload the Like and Dislike count in your view
Kindly do this with livewire
Hello sir,How can count i count likes for perticuler post,
thnk you
You can use something like this: public function getNbLikesAttribute(){return $this->hasMany('app\Like')->count();}
I followed your series and it is very good but I'm facing a problem that when I'm clicking on like/dislike nothing is happening and the data are not being store. When I checked in console then it is showing this error "POST localhost:8000/like 501 (Not Implemented)". Can you help me with this. Thank you.
Hi Vikram, this indicates that there is a an error in your Laravel code. You may click on the erroneous request in the developer tools and you should be able to view the actual response Laravel sent. There, you should see a better error message, explaining what went wrong in your server-side code
Thank you sir for the quick reply. But the thing is I'm very new to this Laravel or coding still I'm in learning phase only so can you elaborate a little more about this one "You may click on the erroneous request in the developer tools " so that I can check the errors and I did exactly what you did in this like series. Can you check my codes and tell me where I'm doing error. This one is my like.js file:-- laravel.io/bin/wJzq9 .
Like.php :-- laravel.io/bin/qQPqV . Migrtaion file:-- laravel.io/bin/0ev9G . This is my FeedsController(Your's PostController): laravel.io/bin/7wv65 . Feed.php :- laravel.io/bin/jQxM9
User.php:-- laravel.io/bin/8KXz5
Hi Vikram,
sorry but I can't do that since you're working on a totally different project. I would have to dig into that first and that simply is a service I can't offer to close to 9.000 subscribers. Simply due to time restrictions.
What I meant with "click on request" is, that in your developer tools you may visit the "Network" tab (assuming Chrome dev tools, but there certainly is an equivalent in FF). You should see a red request there (the erroneous). Click on it and then you should be able to select "Response" somewhere. There, you should see the Laravel error message, which hopefully gets you on the right track to fix this error.
Thanks anyways. I can see the source of the errors but as I don't know anything about the AJAX I'm not able to figure out how to solve that error. Thanks anyways for replying.
But which error message does Laravel give you if you inspect the request (and its response) in the developer tools?
Where is the web.php file sir?
You again don't set foreign key for your like migration. I mean this construction:
$table->foreign('user_id')->references('id')->on('users');
Why?
+Николай Пойманов
Because I don't really need it here. But you are of course free to add this constraint.
Thx!
krasser Typ.
;)
:)
Danke :)
I'm trying to, instead of putting 'Account' in the navbar, place the users first name. My problem is that the $user variable isn't recognized in 'dashboard.blade.php'. Here's a pastebin.com/aMT1Gwvk with my code (thought it would be easier to read there).
You need to make sure to pass your data into that view. Make sure you're doing this when return view('dashboard')
The problem with his tutorials is that you can't really pick up much from them unless you watch the entire videos.
>$post>
this guy is a good teacher but gosh he talks waaaay too much
Sorry to hear that :/
> $post>