php - ErrorException (E_ERROR) 未定义变量:组
问题描述
当我搜索它会显示错误
ErrorException (E_ERROR) 未定义变量:组(查看:C:\xampp\htdocs\ff\Laravel-Webboard-Workshop-master\resources\views\topic\index.blade.php) 以前的异常未定义变量:组(0)
在 route('topic.create', $group->id) 行的主题页面中,这是关于按钮新主题的代码
查看/主题/index.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
@if (! Auth::guest())
<form action="/search_topic" method="get">
<button type="submit" class="btn btn-primary" style="float:right;">Search</button>
<a style="float:right;">
<input type="search" name="search" class="form-control" >
</a>
</form>
<br><br>
<div>
<a href="{{ url('/') }}" style="text-align:left;">
<button type="button" class="btn btn-default">
<span aria-hidden="true"></span>
Back to Home
</button>
</a>
<a href="{{ route('topic.create', $group->id) }}" style="float:right;"> <!--error-->
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
New Topic
</button>
</a>
</div>
<br />
@endif
<div class="panel panel-default">
<div class="panel-heading" style="font-size: 18px;">
Group: {{ $group->title }}
</div>
<div class="panel-body">
<table class="table table-striped table-linkable table-hover">
<thead>
<tr>
<th class="text-center">Topic</th>
<th class="text-center">Posted By</th>
<th class="text-center">Posted At</th>
@if (! Auth::guest())
<th>Edit</th>
<th>Delete</th>
@endif
</tr>
</thead>
<tbody>
@foreach($topics as $topic)
<tr onclick="document.location.href = '{{ action('TopicController@show', $topic->id) }}'">
<td>{{ $topic->title }}</td>
<td class="text-center">{{ $topic->user['name'] }}</td>
<td class="text-center">{{ $topic->created_at->diffForHumans() }}</td>
@if (! Auth::guest())
<td>
@if (Auth::user()->id == $topic->user_id)
<a href="{{ action('TopicController@edit', $topic->id) }}" class="btn btn-warning">Edit</a>
@endif
</td>
<td>
@if (Auth::user()->id == $topic->user_id)
<form method="post" class="delete_form" action="{{action('TopicController@destroy', $topic->id)}}">
{{csrf_field()}}
<input type="hidden" name="_method" value="DELETE" />
<button type="submit" class="btn btn-danger" onclick="return myFunction();">Delete</button>
<script>
function myFunction() {
if(!confirm("Are You Sure to Delete"))
event.preventDefault();
}
</script>
</form>
@endif
</td>
@endif
</tr>
@endforeach
</tbody>
</table>
<div class="text-center">
{!! $topics->links(); !!}
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
模型主题.php
<?php
namespace App;
use App\Group;
use App\Topic;
use Illuminate\Database\Eloquent\Model;
class Topic extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title', 'body'
];
/**
* Get the Comments of a given topic.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments()
{
return $this->hasMany('App\Comment');
}
/**
* Get a user of a given topic
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo('App\User');
}
public function group()
{
return $this->belongsTo('App\Group');
}
}
主题控制器.php
<?php
namespace App\Http\Controllers;
use App\Comment;
use App\Topic;
use App\Group;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
class TopicController extends Controller
{
public function search(Request $request)
{
$search = $request->get('search');
//$groups = DB::table('groups')->where('title', 'like', '%'.$search.'%')->paginate(5);
$topics = Topic::with('user')->where('title', 'like', '%'.$search.'%')->paginate(5);
return view('topic.index', ['topics' => $topics] );
}
}
我应该如何修复这个错误以在我的主题页面中进行搜索?
解决方案
推荐阅读
- python - 从 OpenCv 中的图像中提取墙壁
- c# - 在 Asp.Net 中多次单击按钮时避免页面刷新事件
- javascript - $http.get AngularJS 中的 $event 对象
- c++ - 如何从函数返回动态分配的数组并正确删除它
- jmeter - 在 Linux docker 上测试性能
- css - 使用样式化组件在小型设备上隐藏按钮
- android - 忽略 SimpleXML 路径注释
- go - 如何获取 IP 数据包并注入不同的 VM 和接口
- java - Mockito - 逗号验证参数与逗号分隔列表无顺序
- c++ - 尝试存储文件夹路径时遇到访问冲突,LPSTR/字符串转换中可能出现错误