从数据库中获取数据并在laravel中显示数据库中的值
问题描述:
我想从数据库中获取值并将其显示在视图中,但我没有得到正确的结果。从数据库中获取数据并在laravel中显示数据库中的值
这是我控制器:
class HrRequestController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$hr_request = HrRequest::all();
return array(
'status' => 'success',
'pages' => $hr_request->toArray());
}
}
,这是我型号:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class HrRequest extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'hr_request';
public $timestamps = false;
/**
* Fields.
*
* @var array
*/
protected $fillable = [
'profile_role_id', 'hr_id', 'vacancy', 'experience', 'job_description', 'status', 'viewed',
];
}
view name:view-requests.blade.php
我不知道作如何做到这一点的看法。谁能帮我?
在此先感谢。
答
控制器:
public function index()
{
$hr_request = HrRequest::all();
return view('view-requests')->with('hr_request', $hr_request);
}
检视:
@foreach($hr_request as $row)
<tr>
<td>{{$row->profile_role_id}}</td>
<td>{{$row->vacancy}}</td>
<td>{{$row->experience}}</td>
<td>{{$row->job_description}}</td>
<td>
<button type="button" class="btn btn-primary">View</button>
<button type="button" class="btn btn-success">Edit</button>
<button type="button" class="btn btn-danger">Delete</button>
</td>
</tr>
@endforeach
路线: 路线::得到( '/视图-HR-请求', 'HrRequestController @索引');
It's working ..