Reputation: 91
I cant display data on my view , i think i am doing something wrong with my controller but i dont understand.
my controller
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:
Route::get('test', [
'uses' => 'WelcomeController@index',
'as' => 'welcome',
]);
view:
<div class="panel-body">
<p>Projects: </p>
<p>Users: </p>
<h3>Project: {{ $project->title }} </h3>
what im getting: http://188.166.166.143/test
Upvotes: 1
Views: 72
Reputation: 649
Your Controller:
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);
}
}
And your view should be something like this as Komal said.
<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>
Upvotes: 2
Reputation: 3266
$projects = Projects::get();
will give the collection of projects.
@foreach($projects as $project)
<h3>Project: {{ $project->title }} </h3>
@endforeach
this will give the title of each projects.
Upvotes: 1
Reputation: 2736
public function index()
{
$projects = Projects::all();
return view('welcome')->with('projects', '$projects');
}
Route
Route::get('/test', 'WelcomeController@getIndex');
Your html
<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>
Upvotes: 0