update route.php
Route::get('about', 'PagesController@about');
Browser access URL -> http://localhost/laravel/BATransfer/public/about
Create PagesController
In CLI type
D:\wamp\www\laravel\BATransfer>php artisan make:controller PagesController --plain
app/Http/Controllers/PagesController.php
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Repositories\UserRepository;
class PagesController extends Controller {
public function about(UserRepository $user_gestion){
$users = $user_gestion->index();
return view('pages.about')->with("allUsers", $users);
}
}
app/Models/User
<?php namespace App\Models;
etc....
Create repository
app/Repositories/UserRepository
<?php namespace App\Repositories;
use App\Models\User;
class UserRepository extends BaseRepository {
/**
* Create a new CommentRepository instance.
*
* @param App\Models\Comment $comment
* @return void
*/
public function __construct(User $user)
{
$this->model = $user;
}
/**
* Get comments collection.
*
* @param int $n
* @return Illuminate\Support\Collection
*/
public function index()
{
return $this->model->all();
}
}
resources/views/pages/about.blade.php
<table>
<tr>
<td>ID</td>
<td>Name</td>
</tr>
@foreach($allUsers as $usr)
<tr>
<td>{{ $usr->id }}</td>
<td>{{ $usr->name }}</td>
</tr>
@endforeach
</table>
Route::get('about', 'PagesController@about');
Browser access URL -> http://localhost/laravel/BATransfer/public/about
Create PagesController
In CLI type
D:\wamp\www\laravel\BATransfer>php artisan make:controller PagesController --plain
app/Http/Controllers/PagesController.php
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Repositories\UserRepository;
class PagesController extends Controller {
public function about(UserRepository $user_gestion){
$users = $user_gestion->index();
return view('pages.about')->with("allUsers", $users);
}
}
app/Models/User
<?php namespace App\Models;
etc....
Create repository
app/Repositories/UserRepository
<?php namespace App\Repositories;
use App\Models\User;
class UserRepository extends BaseRepository {
/**
* Create a new CommentRepository instance.
*
* @param App\Models\Comment $comment
* @return void
*/
public function __construct(User $user)
{
$this->model = $user;
}
/**
* Get comments collection.
*
* @param int $n
* @return Illuminate\Support\Collection
*/
public function index()
{
return $this->model->all();
}
}
resources/views/pages/about.blade.php
<table>
<tr>
<td>ID</td>
<td>Name</td>
</tr>
@foreach($allUsers as $usr)
<tr>
<td>{{ $usr->id }}</td>
<td>{{ $usr->name }}</td>
</tr>
@endforeach
</table>
No comments:
Post a Comment