我无法在我的视图中显示数据,我想我的控制器出了问题,但我不明白。
我的控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Projects;
use Auth;
class WelcomeController extends Controller
{
public function __construct(Projects $projects)
{
$this->middleware('auth');
$this->projects = $projects;
}
public function index()
{
$projects = Projects::get();
$this->$projects;
return view('welcome')->with('projects', '$projects');
}
}
路线:
Route::get('test', [
'uses' => 'WelcomeController@index',
'as' => 'welcome',
]);
视图:
<div class="panel-body">
<p>Projects: </p>
<p>Users: </p>
<h3>Project: {{ $project->title }} </h3>
我得到的是什么:http://188.166.166.143/test
答案 0 :(得分:2)
你的控制器:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Projects;
use Auth;
class WelcomeController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$projects = Projects::get();
return view('welcome')->with('projects', $projects);
}
}
你的观点应该像Komal所说的那样。
<table id="table-projects" class="table table-hover">
<thead class="text-center">
<tr>
<th width="10%"><center>Project Name</center></th>
</tr>
</thead>
<tbody>
@foreach($projects as $project)
<tr>
<td>{{$project->title}}</td>
<tr>
@endforeach
</tbody>
</table>
答案 1 :(得分:1)
$projects = Projects::get();
将提供项目集合。
@foreach($projects as $project)
<h3>Project: {{ $project->title }} </h3>
@endforeach
这将给出每个项目的标题。
答案 2 :(得分:0)
text/csv
路线
public function index()
{
$projects = Projects::all();
return view('welcome')->with('projects', '$projects');
}
你的HTML
Route::get('/test', 'WelcomeController@getIndex');