定制 ctl/socialmapfavorites 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ctl/socialmapfavorites

Composer 安装命令:

composer require ctl/socialmapfavorites

包简介

Basic Packaging for Favoriting and Unfavoriting users

README 文档

README

Latest Stable Version Software License Build Status Scrutinizer Code Quality Code Coverage Total Downloads Latest Unstable Version

A PHP Package for Favoriting and Unfavoriting Authenticated Users

Currently only supported for Laravel 5.2

Install

Via Composer

$ composer require ctl/socialmapfavorites

Installation

$ php artisan vendor:publish

Add the service provider to the 'providers' array in config/app.php

CTL\SocialMapFavorites\SocialMapFavoritesServiceProvider::class,

Navigate to App/Jobs/FavAUser. Replace use CTL\SocialMapFavorites\Jobs\Job; with use App\Jobs\Job;

Repeat above with unFavAUser

Navigage to App\Users. Add ActionableTrait like so....

<?php

namespace App;

use Core\Users\ActionableTrait;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract,
                                    AuthorizableContract,
                                    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword, ActionableTrait;

    /**
     * The database table used by the model.

Add "Core\\": "Core/" to your project composer.json. It should look like this...

"psr-4": {
            "App\\": "app/",
            "Core\\": "Core/"
        }

run composer dump-autoload if changes does not take effect.

Change the namespace of Core\Users\ActionableTrait and Core\Users\UsersOrigin

Finally, run....

$ php artisan make:migration CreateFavoritesTable

To create a favs table

Your Migration should look like

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFavoritesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('favs', function(Blueprint $table){
            $table->increments('id');
            $table->integer('favoritee_id')->index();
            $table->integer('favorited_id')->index();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('favs', function(Blueprint $table){
            Schema::drop('favs');
        });
    }
}

Extended Installation

Within blade files..

    @if (!$VariableName->checkFavorited() )
        <div class="btn-group">
          {!! Form::open(['action'=>'ControllerName@store']) !!}
          {!! Form::hidden('userIDToFav', $VariableName->id) !!}

            <button type="submit" class="btn btn-success">Add Fav</button>
          {!! Form::close() !!}
        </div>
    @else
        {!! Form::open(['method' => 'DELETE', 'action' => ['ControllerName@destroy', $VariableName->id] ]) !!}
        {!! Form::hidden('userIDToUnFav', $VariableName->id) !!}
      <div class="btn-group">
        <button type="submit" class="btn btn-primary"><span>Favorited</span></button>
        {!! Form::close() !!}
      </div>
    @endif

Within your controller

    /**
     * Favorite A User
     *
     */
    public function store(Request $request){
      $base = $request->input('userIDToFav');
      $this->dispatch(new FavAUser(\Auth::id(), $base));

      return back();
    }

    /**
     * UnFavorite a user
     *
     */
    public function destroy(Request $request){
      $base = $request->input('userIDToUnFav');
      $this->dispatch(new UnFavAUser(\Auth::id(), $base));

      return back();
    }

For Email Usage

Within the controller

    /**
     * Fav A User
     *
     * @return Response
     */
    public function store(User $user, Request $request)
    {
        $base = array_add($request, 'userID', Auth::id() );
        $clear = $this->dispatchFrom(FavAUserCommand::class, $base);

        // For emailing User Fav
        $findingUserObject = $user->find($request->input('userIDToFav'));
        $this->mail->sendFavAUserNotificationEmail($findingUser, $request->input('userFaved'), Auth::user()->username);


        session()->flash('success_message','You are now following');
        return back();
    }

For $this->mail->sendFavAUserNotificationEmail();

You would need to

    protected $mail;
    protected $usersOrigin;


    /**
    * Class Constructor
    */
    public function __construct(UsersOrigin $usersOrigin, FavAUserMail $mail){

      $this->mail = $mail;
      $this->usersOrigin = $usersOrigin;
    }

Dont forget to add use Core\Users\Mail\FavAUserMail; and use Core\Users\UsersOrigin; at the top of your controller class.

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

License

Eclipse Public License (EPL v1.0). Please see License for more information.

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: EPL
  • 更新时间: 2016-04-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固