php - How to display controller's data -
i cant display data on view , think doing wrong controller 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
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 view should 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 $project) <tr> <td>{{$project->title}}</td> <tr> @endforeach </tbody> </table>
Comments
Post a Comment