PHP code example of ctl / socialmapfavorites
1. Go to this page and download the library: Download ctl/socialmapfavorites library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ctl / socialmapfavorites example snippets bash
$ php artisan vendor:publish
php
CTL\SocialMapFavorites\SocialMapFavoritesServiceProvider::class,
bash
$ php artisan make:migration CreateFavoritesTable
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');
});
}
}
php
/**
* 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();
}
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();
}
php
protected $mail;
protected $usersOrigin;
/**
* Class Constructor
*/
public function __construct(UsersOrigin $usersOrigin, FavAUserMail $mail){
$this->mail = $mail;
$this->usersOrigin = $usersOrigin;
}