2017 © Pedro Peláez
 

library socialmapfavorites

Basic Packaging for Favoriting and Unfavoriting users

image

ctl/socialmapfavorites

Basic Packaging for Favoriting and Unfavoriting users

  • Sunday, December 11, 2016
  • by mr.jessop
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Social Map Favorites

Latest Stable Version Software License Build Status Scrutinizer Code Quality Code Coverage Total Downloads Latest Unstable Version, (*1)

A PHP Package for Favoriting and Unfavoriting Authenticated Users, (*2)

Currently only supported for Laravel 5.2, (*3)

Install

Via Composer, (*4)

``` bash $ composer require ctl/socialmapfavorites, (*5)


## Installation ``` bash $ php artisan vendor:publish

Add the service provider to the 'providers' array in config/app.php, (*6)

``` php CTL\SocialMapFavorites\SocialMapFavoritesServiceProvider::class,, (*7)


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 <?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..., (*8)

``` json "psr-4": { "App\": "app/", "Core\": "Core/" }, (*9)


run `composer dump-autoload` if changes does not take effect. *Change the `namespace` of `Core\Users\ActionableTrait` and `Core\Users\UsersOrigin`* Finally, run.... ``` bash $ php artisan make:migration CreateFavoritesTable

To create a favs table, (*10)

Your Migration should look like, (*11)

``` php <?php, (*12)

use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;, (*13)

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(); }); }, (*14)

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

}, (*15)

### Extended Installation

Within blade files..

``` php
    @if (!$VariableName->checkFavorited() )


{!! Form::open(['action'=>'ControllerName@store']) !!} {!! Form::hidden('userIDToFav', $VariableName->id) !!} {!! Form::close() !!}
@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, (*16)

``` php, (*17)

/**
 * 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 ``` php /** * 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();, (*18)

You would need to, (*19)

``` php, (*20)

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 ``` bash $ phpunit

Contributing

Please see CONTRIBUTING for details., (*21)

License

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

The Versions