我已向我的 auth 用户添加了一个角色列,它扩展了角色表
角色迁移
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('description');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('roles');
}
}
Run Code Online (Sandbox Code Playgroud)
用户迁移
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/ …Run Code Online (Sandbox Code Playgroud) 如果查询在数据库中没有匹配项,我希望得到“未找到”结果。
这是我的result.blade.php:
@extends('layouts.app')
@section('content')
@foreach ($result as $object)
<div class="container pb-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h3>Details for the animal</h3>
</div>
<div class="card-body">
<div class="col-12">
<p><strong>Serial Number: </strong>{{ $object->reference }}</p>
<p><strong>Animal Type: </strong>{{ $object->animal->type->category }}</p>
<p><strong>Farm: </strong>{{ $object->animal->user->name }}</p>
<p><strong>Date Of Birth: </strong>{{ $object->animal->dateOfBirth }}</p>
<p><strong>Farm Location: </strong>{{ $object->animal->user->address->city }}</p>
<p><strong>Clinic: </strong>{{ $object->animal->clinic->user->name ?? 'Was Not Checked by a Clinic' }}</p>
<p><strong>Clinic Location: </strong>{{ $object->animal->clinic->user->address->city }}</p>
<p><strong>Vaccination: </strong>
{{ $object->animal->clinic->vaccine1 ?? 'N/A' }},
{{ …Run Code Online (Sandbox Code Playgroud)