这是AdminController.php:
<?php
namespace App\Http\Controllers;
use Response;
use Illuminate\Support\Facades\DB;
use App\Caption;
use App\Image;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
public function admin() {
$images = Image::paginate();
return view('admin',[ '$images' => $images]);
}
}
这是admin.blade.php:
@extends('template')
@section('title')
Admin Page
@endsection
@section('header')
@endsection
@section('main')
@if (Auth::check())
@foreach ($images as $image)
<p value='{{$image->id}}'>{{$image->content}}</p>
<form action="image/{{$image->id}}/delete" method="post">
<button type="submit">Delete caption</button>
</form>
<form action="image/{{$image->id}}/approve" method="post">
<button type="submit">Accept image</button>
</form>
@endforeach
@else
<p>Login first</p>
@endif
@endsection
@section('footer')
@endsection
为什么我会收到以下错误?
ErrorException in 408148d5409ae6eebf768dc5721bd0d1d9af48af.php line 9:
Undefined variable: images (View: /Users/sahandz/Documents/School/Singapore/CS3226/backend/resources/views/admin.blade.php)
$images在我的控制器中明确定义.
谢谢.
解决方法:
在将数据传递给视图时,您已使用$images作为变量名.这导致刀片创建一个名为$$图像的变量.
return view('admin',[ 'images' => $images]);
将导致视图创建一个名为$images的变量
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。