<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>laravel dislike Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/laravel-dislike/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/laravel-dislike/</link>
	<description>Code Solution</description>
	<lastBuildDate>Mon, 10 May 2021 00:27:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>laravel dislike Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/laravel-dislike/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Laravel 8 Like Dislike Example</title>
		<link>https://codeplaners.com/laravel-8-like-dislike-example/</link>
					<comments>https://codeplaners.com/laravel-8-like-dislike-example/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 10 May 2021 00:09:01 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[laravel dislike]]></category>
		<category><![CDATA[laravel like]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=661</guid>

					<description><![CDATA[<p>Today, i we will show you Laravel 8 Like Dislike Example. This article will give you simple example of Laravel 8 Like Dislike Example. you will learn Laravel 8 Like Dislike Example. step by step explain Laravel 8 Like Dislike Example. For making it i will use &#8220;overture/laravel-follow&#8221; composer package to create follow unfollow system &#8230; <a href="https://codeplaners.com/laravel-8-like-dislike-example/" class="more-link">Continue reading<span class="screen-reader-text"> "Laravel 8 Like Dislike Example"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-8-like-dislike-example/">Laravel 8 Like Dislike Example</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today, i we will show you Laravel 8 Like Dislike Example. This article will give you simple example of Laravel 8 Like Dislike Example. you will learn Laravel 8 Like Dislike Example. step by step explain Laravel 8 Like Dislike Example.</p>
<p>For making it i will use &#8220;overture/laravel-follow&#8221; composer package to create follow unfollow system in Laravel.</p>
<h3>Step 1 :- Install Laravel</h3>
<pre class="brush: php; title: ; notranslate">
composer create-project --prefer-dist laravel/laravel blog
</pre>
<p><strong>Connect Database .env</strong></p>
<pre class="brush: php; title: ; notranslate">
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=databse
DB_USERNAME=root
DB_PASSWORD=
</pre>
<h3>Step 2 :- Install overtrue/laravel-follow Package</h3>
<pre class="brush: php; title: ; notranslate">
composer require overtrue/laravel-follow -vvv
</pre>
<p>Now open <strong>config/app.php</strong> file and add service provider and aliase.</p>
<p><strong>config/app.php</strong></p>
<pre class="brush: php; title: ; notranslate">
'providers' =&gt; &#x5B;
	Overtrue\LaravelFollow\FollowServiceProvider::class,
],
</pre>
<p>To publish the migrations file run bellow command.</p>
<pre class="brush: php; title: ; notranslate">
php artisan vendor:publish --provider='Overtrue\LaravelFollow\FollowServiceProvider' --tag=&quot;migrations&quot;
</pre>
<p>As optional if you want to modify the default configuration, you can publish the configuration file.</p>
<pre class="brush: php; title: ; notranslate">
php artisan vendor:publish --provider=&quot;Overtrue\LaravelFollow\FollowServiceProvider&quot; --tag=&quot;config&quot;
</pre>
<p>Then just migrate it by using following command</p>
<pre class="brush: php; title: ; notranslate">
php artisan migrate
</pre>
<h3>Step 3 :- Create Authentication</h3>
<pre class="brush: php; title: ; notranslate">
php artisan make:auth
</pre>
<h3>Step 4 :- Create Posts</h3>
<pre class="brush: php; title: ; notranslate">
php artisan make:migration create_posts_table
</pre>
<p><strong>database/migrations/CreatePostsTable.php</strong></p>
<pre class="brush: php; title: ; notranslate">
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration
{
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table-&gt;increments('id');
            $table-&gt;string('title');
            $table-&gt;timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('posts');
    }
}
</pre>
<pre class="brush: php; title: ; notranslate">
php artisan migrate
</pre>
<p>After this we need to create model for posts table by following path.<br />
<strong>App/Post.php</strong></p>
<pre class="brush: php; title: ; notranslate">
namespace App;

use Overtrue\LaravelFollow\Traits\CanBeLiked;
use Illuminate\Database\Eloquent\Model;


class Post extends Model
{
	use CanBeLiked;

    protected $fillable = &#x5B;'title'];
}
</pre>
<p>Now we require to create some dummy posts data on database table so create laravel seed using bellow command:</p>
<pre class="brush: php; title: ; notranslate">
php artisan make:seeder CreateDummyPost
</pre>
<p>update CreateDummyPost seeds like as bellow:<br />
<strong>database/seeds/CreateDummyPost.php</strong></p>
<pre class="brush: php; title: ; notranslate">
use Illuminate\Database\Seeder;
use App\Post;

class CreateDummyPost extends Seeder
{
  
    public function run()
    {
        $posts = &#x5B;'codechief.org', 'wordpress.org', 'laramust.com'];

        foreach ($posts as $key =&gt; $value) {
        	Post::create(&#x5B;'title'=&gt;$value]);
        }
    }
}
</pre>
<p>Run seeder using this command.</p>
<pre class="brush: php; title: ; notranslate">
php artisan db:seed --class=CreateDummyPost
</pre>
<h3>Step 5 :- Update User Model</h3>
<p><strong>App/User.php</strong></p>
<pre class="brush: php; title: ; notranslate">
namespace App;

use Overtrue\LaravelFollow\Traits\CanLike;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;


class User extends Authenticatable
{
    use CanLike, Notifiable ; //Notice we used CanLike trait

    protected $fillable = &#x5B;
        'name', 'email', 'password',
    ];

    protected $hidden = &#x5B;
        'password', 'remember_token',
    ];
}
</pre>
<h3>Step 6 :- Create Routes</h3>
<p><strong>routes/web.php</strong></p>
<pre class="brush: php; title: ; notranslate">
Route::get('/home', 'HomeController@index')-&gt;name('home');
Route::get('posts', 'HomeController@posts')-&gt;name('posts');
Route::post('like', 'HomeController@LikePost')-&gt;name('like');
</pre>
<h3>Step 7 :- Add Controller</h3>
<p><strong>app/Http/HomeController.php</strong></p>
<pre class="brush: php; title: ; notranslate">
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;
use App\User;


class HomeController extends Controller
{
    public function __construct()
    {
        $this-&gt;middleware('auth');
    }

    public function index()
    {
        return view('home');
    }

    public function posts()
    {
        $posts = Post::get();
        return view('posts', compact('posts'));
    }

    public function LikePost(Request $request){

        $post = Post::find($request-&gt;id);
        $response = auth()-&gt;user()-&gt;toggleLike($post);

        return response()-&gt;json(&#x5B;'success'=&gt;$response]);
    }
}
</pre>
<h3>Step 8 :- Add Blade file</h3>
<p><strong>resources/views/posts.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
@extends('layouts.app')

@section('content')
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css&quot;&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js&quot;&gt;&lt;/script&gt;

&lt;meta name=&quot;csrf-token&quot; content=&quot;{{ csrf_token() }}&quot; /&gt;

&lt;link href=&quot;{{ asset('css/custom.css') }}&quot; rel=&quot;stylesheet&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;row justify-content-center&quot;&gt;
        &lt;div class=&quot;col-md-12&quot;&gt;
            &lt;div class=&quot;card&quot;&gt;
                &lt;div class=&quot;card-header&quot;&gt;Posts&lt;/div&gt;

                &lt;div class=&quot;card-body&quot;&gt;
                    @if($posts-&gt;count())
                        @foreach($posts as $post)
                            &lt;article class=&quot;col-xs-12 col-sm-6 col-md-3&quot;&gt;
                                &lt;div class=&quot;panel panel-info&quot; data-id=&quot;{{ $post-&gt;id }}&quot;&gt;
                                    &lt;div class=&quot;panel-body&quot;&gt;
                                        &lt;a href=&quot;https://www.codechief.org/user/img/user.jpg&quot; title=&quot;Nature Portfolio&quot; data-title=&quot;Amazing Nature&quot; data-footer=&quot;The beauty of nature&quot; data-type=&quot;image&quot; data-toggle=&quot;lightbox&quot;&gt;
                                    &lt;img src=&quot;https://www.codechief.org/user/img/user.jpg&quot; style=&quot;height: 50px; width: 50px; border-radius: 50%;&quot;&gt;
                                            &lt;span class=&quot;overlay&quot;&gt;&lt;i class=&quot;fa fa-search&quot;&gt;&lt;/i&gt;&lt;/span&gt;
                                        &lt;/a&gt;
                                    &lt;/div&gt;  
                                    &lt;div class=&quot;panel-footer&quot;&gt;
                                        &lt;h4&gt;&lt;a href=&quot;#&quot; title=&quot;Nature Portfolio&quot;&gt;{{ $post-&gt;title }}&lt;/a&gt;&lt;/h4&gt;
                                        &lt;span class=&quot;pull-right&quot;&gt;
                                            &lt;span class=&quot;like-btn&quot;&gt;
                                                &lt;i id=&quot;like{{$post-&gt;id}}&quot; class=&quot;glyphicon glyphicon-thumbs-up {{ auth()-&gt;user()-&gt;hasLiked($post) ? 'like-post' : '' }}&quot;&gt;&lt;/i&gt; &lt;div id=&quot;like{{$post-&gt;id}}-bs3&quot;&gt;{{ $post-&gt;likers()-&gt;get()-&gt;count() }}&lt;/div&gt;
                                            &lt;/span&gt;
                                        &lt;/span&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;
                            &lt;/article&gt;
                        @endforeach
                    @endif
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
    $(document).ready(function() {     

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta&#x5B;name=&quot;csrf-token&quot;]').attr('content')
            }
        });

        $('i.glyphicon-thumbs-up, i.glyphicon-thumbs-down').click(function(){    
            var id = $(this).parents(&quot;.panel&quot;).data('id');
            var c = $('#'+this.id+'-bs3').html();
            var cObjId = this.id;
            var cObj = $(this);

            $.ajax({
               type:'POST',
               url:'/like',
               data:{id:id},
               success:function(data){
                  if(jQuery.isEmptyObject(data.success.attached)){
                    $('#'+cObjId+'-bs3').html(parseInt(c)-1);
                    $(cObj).removeClass(&quot;like-post&quot;);
                  }else{
                    $('#'+cObjId+'-bs3').html(parseInt(c)+1);
                    $(cObj).addClass(&quot;like-post&quot;);
                  }
               }
            });

        });      

        $(document).delegate('*&#x5B;data-toggle=&quot;lightbox&quot;]', 'click', function(event) {
            event.preventDefault();
            $(this).ekkoLightbox();
        });                                        
    }); 
&lt;/script&gt;
@endsection 
</pre>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-8-like-dislike-example/">Laravel 8 Like Dislike Example</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/laravel-8-like-dislike-example/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
