Answer the question
In order to leave comments, you need to log in
How to get one record from the database?
How can I get one specific record from the database? My solution doesn't work because I don't understand how to put in the id variable, which specifies the post number. If instead $id
of writing some number, then everything works
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
class TestController extends Controller
{
public function show($id)
{
$result = DB::select('select * from users where id = ?', [$id]);
foreach($result as $item){
$login = $item->login;
$password = $item->password;
}
return view('test',[
'login' => $login,
'password' => $password,
]);
}
}
?>
Answer the question
In order to leave comments, you need to log in
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\User;
class TestController extends Controller
{
public function show($id)
{
$user = User::findOrFail($id);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question