完成 link工厂类 查询路由

This commit is contained in:
lingling 2022-07-08 17:04:09 +08:00
parent 4530a92837
commit 8036c6ac3a
7 changed files with 109 additions and 10 deletions

View File

@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Link;
class UController extends ApiController
{
/**
@ -70,6 +72,9 @@ class UController extends ApiController
{
//
//return json_encode($request);
return $this->create('请求成功',200, $data = $request->all());
$data = $request->all();
$link = Link::where('id',$data['id'])->first();
return $this->create('请求成功',200,$link);
}
}

11
app/Models/Link.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Link extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Link>
*/
class LinkFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
//
'url' => Str::random(10),
];
}
}

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('links', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('links');
}
};

View File

@ -5,10 +5,9 @@ namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
use App\Models\Link;
class DatabaseSeeder extends Seeder
{
@ -21,15 +20,18 @@ class DatabaseSeeder extends Seeder
{
// \App\Models\User::factory(10)->create();
\App\Models\User::factory()->create([
'name' => Str::random(10),
'email' => Str::random(10).'@gmail.com',
'password' => Hash::make('password')
]);
// \App\Models\User::factory()->create([
// 'name' => Str::random(10),
// '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();
$this->call([
LinkSeeder::class
]);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
class LinkSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
\App\Models\Link::factory()->create([
'url' => Str::random(10),
]);
}
}

View File

@ -15,6 +15,6 @@ class UserSeeder extends Seeder
public function run()
{
//
User::factory(50)->create();
//User::factory(50)->create();
}
}