2020-03-21 17:30:44 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Texture;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class ClosetManagementController extends Controller
|
|
|
|
{
|
2020-05-01 22:52:43 +08:00
|
|
|
public function list($uid)
|
|
|
|
{
|
|
|
|
/** @var User */
|
|
|
|
$user = User::findOrFail($uid);
|
|
|
|
|
|
|
|
return $user->closet;
|
|
|
|
}
|
|
|
|
|
2020-03-21 17:30:44 +08:00
|
|
|
public function add(Request $request, $uid)
|
|
|
|
{
|
|
|
|
/** @var Texture */
|
|
|
|
$texture = Texture::findOrFail($request->input('tid'));
|
|
|
|
|
|
|
|
/** @var User */
|
|
|
|
$user = User::findOrFail($uid);
|
|
|
|
$user->closet()->attach($texture->tid, ['item_name' => $texture->name]);
|
|
|
|
|
|
|
|
return json('', 0, compact('user', 'texture'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove(Request $request, $uid)
|
|
|
|
{
|
|
|
|
/** @var Texture */
|
|
|
|
$texture = Texture::findOrFail($request->input('tid'));
|
|
|
|
|
|
|
|
/** @var User */
|
|
|
|
$user = User::findOrFail($uid);
|
|
|
|
$user->closet()->detach($texture->tid);
|
|
|
|
|
|
|
|
return json('', 0, compact('user', 'texture'));
|
|
|
|
}
|
|
|
|
}
|