添加了 工厂模型 但是一次只能创建一家 添加了 api控制器 用于统一api返回结果
This commit is contained in:
parent
b78e3fb983
commit
4530a92837
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ApiController extends Controller
|
||||||
|
{
|
||||||
|
protected function create($msg = '', $code = 200, $data = [])
|
||||||
|
{
|
||||||
|
$result = [
|
||||||
|
// 返回状态码
|
||||||
|
'code'=>$code,
|
||||||
|
// 返回提示信息
|
||||||
|
'msg'=>$msg,
|
||||||
|
// 返回数据
|
||||||
|
'data'=>$data,
|
||||||
|
];
|
||||||
|
return response($result);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class UController extends Controller
|
class UController extends ApiController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
|
@ -66,4 +66,10 @@ class UController extends Controller
|
||||||
//
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public function text(Request $request)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
//return json_encode($request);
|
||||||
|
return $this->create('请求成功',200, $data = $request->all());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Flight extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
}
|
|
@ -5,6 +5,11 @@ namespace Database\Seeders;
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
class DatabaseSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -16,9 +21,15 @@ class DatabaseSeeder extends Seeder
|
||||||
{
|
{
|
||||||
// \App\Models\User::factory(10)->create();
|
// \App\Models\User::factory(10)->create();
|
||||||
|
|
||||||
// \App\Models\User::factory()->create([
|
\App\Models\User::factory()->create([
|
||||||
// 'name' => 'Test User',
|
'name' => Str::random(10),
|
||||||
// 'email' => 'test@example.com',
|
'email' => Str::random(10).'@gmail.com',
|
||||||
// ]);
|
'password' => Hash::make('password')
|
||||||
|
]);
|
||||||
|
// $user=new User;
|
||||||
|
// $user->name=Str::random(10);
|
||||||
|
// $user->email=Str::random(10).'@gmail.com';
|
||||||
|
// $user->password=Hash::make('password');
|
||||||
|
// $user->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class UserSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
User::factory(50)->create();
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,3 +26,4 @@ use App\Http\Controllers\UController;
|
||||||
// });
|
// });
|
||||||
Route::get('/link/{id}', [UController::class, 'index']);
|
Route::get('/link/{id}', [UController::class, 'index']);
|
||||||
Route::post('/link/{url}', [UController::class, 'add']);
|
Route::post('/link/{url}', [UController::class, 'add']);
|
||||||
|
Route::post('/text', [UController::class, 'text']);
|
||||||
|
|
Loading…
Reference in New Issue