完成了api的添加功能 获取功能 定时暂时未完成

This commit is contained in:
lingling 2022-07-08 17:25:26 +08:00
parent 8036c6ac3a
commit e6a7ba9455
4 changed files with 13 additions and 6 deletions

View File

@ -16,7 +16,9 @@ class UController extends ApiController
public function index($id)
{
//
return $id;
$link = Link::where('id',$id)->first();
return base64_encode($link['url']);
}
/**
@ -63,9 +65,12 @@ class UController extends ApiController
{
//
}
public function add($url)
public function add(Request $request)
{
//
$data = $request->all();
$link = Link::create(['url' => $data['url']]);
return $this->create('请求成功',200,$link);
}
public function text(Request $request)
@ -74,7 +79,6 @@ class UController extends ApiController
//return json_encode($request);
$data = $request->all();
$link = Link::where('id',$data['id'])->first();
return $this->create('请求成功',200,$link);
}
}

View File

@ -8,4 +8,7 @@ use Illuminate\Database\Eloquent\Model;
class Link extends Model
{
use HasFactory;
protected $fillable = [
'url',
];
}

View File

@ -25,5 +25,5 @@ use App\Http\Controllers\UController;
// Route::get('/users','App\Http\Controllers\UserController@index');
// });
Route::get('/link/{id}', [UController::class, 'index']);
Route::post('/link/{url}', [UController::class, 'add']);
Route::post('/addlink', [UController::class, 'add']);
Route::post('/text', [UController::class, 'text']);

View File

@ -2,7 +2,7 @@
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\UController;
/*
|--------------------------------------------------------------------------
| Web Routes
@ -18,4 +18,4 @@ Route::get('/', function () {
//return view('welcome');
return "dwa";
});
//Route::get('/d','App\Http\Controllers\Api\UserController@index');
Route::get('/link/{id}', [UController::class, 'index']);