Last active
April 18, 2024 13:24
-
-
Save Sentinel17/2da2a794dc73474e70409d48a2dec488 to your computer and use it in GitHub Desktop.
Laravel ДЗ №2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::get('users', 'UsersController@allAction'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment