控制器,rawSQL,Model
controller.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests;
use DB; class MyController extends Controller
{
public function hello()
{ $articles = DB::select('select * from posts'); return View('myview',['d1'=>$articles]);
}
}
这里控制器给blade页面传递了一个数组,这个数组是直接通过数据库查询来的。
*.blade.php
@extends('layouts.app') @section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">{{ count($d1) }}</div> <div class="panel-body">
this is my view!
</div> @for($i = 0; $i < count($d1); $i++)
<p>{{ $d1[$i]->content }}</p>
@endfor </div>
</div>
</div>
</div>
@endsection