我在查看时遇到麻烦。这是我的控制器:
// Instead of this
import { ExampleService } from '@lib/services/example.service';
import { AntoherService } from '@lib/sevivces/another.service';
// You can do this
import { ExmpaleService, AnotherService } from '@lib';
视图:
public function index()
{
$images=ImageUpload::all();
return view('index', compact('images'));
}
我的路线:
@foreach ($images as $image)
<p>{{$image->title}}</p>
@endforeach
我已经尝试过:
Route::post('upload','imageController@index');
&
return view('index')->with('images', $images);
&
return view('index')->with(compact('images'));
我的错误:
未定义变量:图片(视图:C:\ Users \ Aioro \ Desktop \ webcomiclaravel \ resources \ views \ index.blade.php)
答案 0 :(得分:-2)
在您的ImageUpload模型中
您还将定义
class ImageUpload extends Model
{
protected $table = 'your table name';
protected $fillable = [
'title'
];
在您的控制器中
public function index()
{
$images=ImageUpload::get();
return view('index', compact('images'));
}
在您的web.php中
Route::post('upload','imageController@index');
在您的index.blade.php
@foreach ($images as $image)
<p>{{$image->title}}</p>
@endforeach