2016-10-10 7 views
1

私は、データベースからデータを出力悩みを持っている、それは画像やHTMLファイルのファイルの場所ですが、私は取得していますエラーは次のとおりです。は、画像とhtmlファイルを表示することはできません - laravel

未定義のプロパティ:雄弁\コレクション\ \データベースを照らす:: $の画像(閲覧:C:\ xamppの\ htdocsに\ fyproject \リソース\ビュー\レイアウト\ homepage.blade.php)

マイコード:

ビュー:

@extends('layouts.master') 

@section('title', 'Best programmer ever') 

@section('content') 
    <h1>Home Page</h1> 
@endsection 
     @section('template') 
      <!-- <img src="{{asset('img/1.jpg')}}">--> 
      @foreach ($templates as $template) 
      {{$templates->image}} 
      {{$templates->file}} 
     @endforeach 
     @show 

コントローラー:

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

use App\Template; 

class BuilderController extends Controller 
{ 
    function templates() 
    { 
     $templates = Template::all(); 
     return view('layouts/homepage', ['templates' => $templates]); 
    } 
} 

モデル:私はどんな関係がdefinnedしていないこれが唯一のテーブルであるデータベース

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Template extends Model 
{ 
    // 
} 

私が間違って何をやっているのですか?

答えて

1

foreachループの内部では、 "テンプレートとして"定義している間に、 "テンプレート"ではなく "テンプレートS"を使用しています。だから、このような単純なミスが...私は今それを修正することができる方法上の任意のアイデアはにテキストから変更するには、{{$テンプレート - >何か}}

+0

の神私のああを使用実際の画像/ファイルはテキストではなく表示されるようになります。 –

+0

img src = "{{asset( 'img /'。$ template-> image)} –

+0

画像であるというアイコンが表示されます。表示されない –

0
@foreach ($templates as $template) 
      {{$template->image}} 
      {{$template->file}} 
@endforeach 

テンプレートではないテンプレート^^

+0

ええ、私はちょうど、これらの単純な間違いを作ることを告げられているhaha、ありがとう –

関連する問題