Skip to content

Instantly share code, notes, and snippets.

@Sentinel17
Last active April 18, 2024 13:24
Show Gist options
  • Save Sentinel17/2da2a794dc73474e70409d48a2dec488 to your computer and use it in GitHub Desktop.
Save Sentinel17/2da2a794dc73474e70409d48a2dec488 to your computer and use it in GitHub Desktop.
Laravel ДЗ №2
<?php
namespace App\Models;
use Illuminate\Support\Facades\DB;
class ModelBaseFunction {
private $table_name = 'users';
public function getAllUsers(){
return DB::select('select * from users');
}
public function getCountUsers(){
return DB::table($this->table_name)->count();
}
public function getUserById() {
$id=DB::table($this->table_name)
->where('id', 1)
->first();
}
}
<span>Количество записей: {{$countUsers}}</span>
<table cellspacing="3" border="2" cellpadding="5">
<tr>
<th>id</th>
<th>Логин</th>
<th>Пароль</th>
</tr>
@foreach ($allUsers as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->login}}</td>
<td>{{$user->password}}</td>
</tr>
@endforeach
</table>
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\ModelBaseFunction;
class UsersController extends Controller
{
public function allAction(){
$user = new ModelBaseFunction();
$allUsers = $user->getAllUsers();
$countUsers = $user->getCountUsers();
$idUser = $user->getUserById();
return view('users', ['allUsers'=>$allUsers], ['countUsers'=>$countUsers], ['idUser'=>$idUser]);
}
}
<?php
Route::get('users', 'UsersController@allAction');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment