昨天学习了query builder
今天我们的目的就是要建立评分表
所谓评分表理当应该是除了自己以外,对其他人的技能评分
当然自己不能评分到自己的技能 !!
就跟特级厨师测验一样~
php artisan make:model Point -m
我们先建立point的资料model模型 并且建立migration
在database/migrations/create_points_table.php里面修改
public function up()
{
Schema::create('points', function (Blueprint $table) {
$table->id();
$table->integer('skill_id');
$table->integer('user_id');
$table->integer('judge_user_id');
$table->integer('point');
$table->timestamps();
});
}
这边的目的主要是我们评分表要记录
接者就下指令
php artisan migrate
先下指令因为我们route要使用resource方法对应controller
没有controllrt会报错误
php artisan make:controller PointController --resource
我们一样先把CRUD建好
在web.php里面加入
Route::resource('points', 'PointController');
我们先到Model Point增加前端要传的fillable参数
class Point extends Model
{
use HasFactory;
protected $fillable = [
'point', 'user_id', 'judge_user_id', 'skill_id'
];
}
接者我们来到point的controller里面
我们来修改一下index function
public function index()
{
//
if (Auth::check()) {
$user = Auth::user();
$skills = Skill::query()->where('user_id', '!=', $user->id)->get();
// dd($filterSkills);
return view('point.index', ['skills' => $skills]);
}
return view('user.login');
}
评分顾名思义就是要评别人,我们这边要先判断使用者是谁就要先进行登入
第二步骤再来判断使用者是谁,接者过滤掉除了该使用者後捞取技能来评分
我这边登入的使用者是roni
所以只会显示 admin 的技能 化学 单一项目
接者我们把view新增一个point的资料夹
我们要来做point的前端介面
各位小可爱应该也有发现惹这边我们可以copy skill的来使用
我们先copy skill的使用
接者修改参数吧!!
这个档案
views/point/index.blade.php
<head>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<div>
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>标题</th>
<th>使用者ID</th>
<th>技能评分</th>
</tr>
</thead>
<tbody>
@foreach($skills as $skill )
<tr>
<td>{{$skill->id}}</td>
<td>{{$skill->title}}</td>
<td>{{$skill->user_id}}</td>
<td><button type="button" class="btn btn-primary">进入评分</button></td>
</tr>
@endforeach
</tbody>
</table>
</div>
我们先把controllrt filter的skill筛进去
接者多增加一个button吧
今天先完成到这边明天把评分 跟列表串完吧!!
>>: #24 No-code 之旅 — 在 Next.js 专案中实作 API
欢迎来到「30 天 Java 从陌生到更陌生」 我是 Piglet,接下来的 30 天,会带着初踏入...
今天把昨天写的选取器跟显示东西做串接 首先先写一个json,若会用firebase或App Scri...
BERT输出了什麽? 回应上一篇关於词嵌入Token Embedding的讨论,BERT的输出就是文...
显示声波图形 教学原文参考:显示声波图形 这篇文章会介绍,在 Scratch 3 里侦测麦克风的声音...
UML (统一建模语言),对於所有学过 OOP 语言的人是一个耳熟能详的图表,UML, SysML,...