mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update
This commit is contained in:
parent
aceff450ec
commit
b8c8335542
53
app/Http/Controllers/Admin/TutorialController.php
Normal file
53
app/Http/Controllers/Admin/TutorialController.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\TutorialSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Tutorial;
|
||||
|
||||
class TutorialController extends Controller
|
||||
{
|
||||
public function fetch (Request $request) {
|
||||
return response([
|
||||
'data' => Tutorial::all()
|
||||
]);
|
||||
}
|
||||
|
||||
public function save (TutorialSave $request) {
|
||||
$params = $request->only([
|
||||
'title',
|
||||
'description'
|
||||
]);
|
||||
|
||||
if (!$request->input('id')) {
|
||||
if (!Tutorial::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
} else {
|
||||
if (!Tutorial::find($request->input('id'))->update($params)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function show (Request $request) {
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$tutorial = Tutorial::find($request->input('id'));
|
||||
$tutorial->show = $tutorial->show ? 0 : 1;
|
||||
if (!$tutorial->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
29
app/Http/Requests/Admin/TutorialSave.php
Normal file
29
app/Http/Requests/Admin/TutorialSave.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TutorialSave extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'title' => 'required',
|
||||
'description' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'title.required' => '标题不能为空',
|
||||
'description.required' => '描述不能为空',
|
||||
];
|
||||
}
|
||||
}
|
@ -59,6 +59,10 @@ Route::prefix('v1')
|
||||
// Coupon
|
||||
Route::get ('coupon/fetch', 'Admin\\CouponController@fetch');
|
||||
Route::post('coupon/save', 'Admin\\CouponController@save');
|
||||
// Tutorial
|
||||
Route::get ('tutorial/fetch', 'Admin\\TutorialController@fetch');
|
||||
Route::post('tutorial/save', 'Admin\\TutorialController@save');
|
||||
Route::post('tutorial/show', 'Admin\\TutorialController@show');
|
||||
});
|
||||
// User
|
||||
Route::prefix('user')
|
||||
|
12
update.sql
12
update.sql
@ -105,4 +105,14 @@ CREATE TABLE `v2_coupon` (
|
||||
);
|
||||
|
||||
ALTER TABLE `v2_order`
|
||||
ADD `discount_amount` int(11) NULL AFTER `total_amount`;
|
||||
ADD `discount_amount` int(11) NULL AFTER `total_amount`;
|
||||
|
||||
CREATE TABLE `v2_tutorial` (
|
||||
`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`title` varchar(255) COLLATE 'utf8mb4_general_ci' NOT NULL,
|
||||
`description` varchar(255) COLLATE 'utf8mb4_general_ci' NOT NULL,
|
||||
`steps` text NULL,
|
||||
`show` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL
|
||||
);
|
Loading…
Reference in New Issue
Block a user