Вариант для C ++:
#include <regex> // Required include
...
// Source string
std::wstring srcStr = L"String with GIUD: {4d36e96e-e325-11ce-bfc1-08002be10318} any text";
// Regex and match
std::wsmatch match;
std::wregex rx(L"(\\{[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\\})", std::regex_constants::icase);
// Search
std::regex_search(srcStr, match, rx);
// Result
std::wstring strGUID = match[1];
Я предлагаю вам для маршрута
Route::post('users/{id}/action', 'API\UserController@action');
и для запроса тела:
{
"act":"follow" //or unfollow
}
таблица:
public function up()
{
Schema::create('action_logs', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('object_id')->unsigned();
$table->enum('object_type',['USER','PAGE','POST']);
$table->enum('act',['FOLLOW','UNFOLLOW','VISIT' ,'LIKE','DISLIKE']);
$table->timestamp('created_at');
$table->foreign('user_id')->references('id')->on('users')
->onDelete('restrict')
->onUpdate('restrict');
});
//Or to make it easier
Schema::create('follower_following', function (Blueprint $table) {
$table->integer('follower_id')->unsigned();
$table->integer('following_id')->unsigned();
$table->primary(array('follower_id', 'following_id'));
$table->foreign('follower_id')->references('id')->on('users')
->onDelete('restrict')
->onUpdate('restrict');
$table->foreign('following_id')->references('id')->on('users')
->onDelete('restrict')
->onUpdate('restrict');
});
в модели (user.php) [ 118]
public function followers()
{
return $this->belongsToMany('App\User', 'follower_following', 'following_id', 'follower_id')
->select('id', 'username', 'name','uid');
}
public function following()
{
return $this->belongsToMany('App\User', 'follower_following', 'follower_id', 'following_id')
->select('id', 'username', 'name','uid');
}
метод действия: (если у вас есть страница и другой объект ... Лучше использовать этот метод в качестве черты)
public function action($id, Request $request)
{
// $user
switch ($request->get('act')) {
case "follow":
$user->following()->attach($id);
//response {"status":true}
break;
case "unfollow":
$user->following()->detach($id);
//response {"status":true}
break;
default:
//response {"status":false, "error" : ['wrong act']}
}
}