我试图将数据从控制器传递到我的视图。
-------- -------- edit_request.blade.php
library(rpart)
library(rpart.plot)
library("quantmod")
startDate = as.Date("2012-01-01")
endDate = as.Date("2014-01-01")
getSymbols("005930", src = "google", from = startDate, to = endDate)
我的数据应来自我的数据库,而且我不知道如何在我的控制器中构建它。
-------- --------- AdminController.php
@extends('layout')
@section('content')
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title"><?= $title ?></h3>
</div><!-- /.box-header -->
<!-- form start -->
<form method="post" id="main-form" action="" enctype="multipart/form-data">
<input type="hidden" name="id" value="???">
<div class="box-body">
<div class="form-group">
<label>Driver's name</label>
<input type="text" class="form-control" name="first_name" value="???" placeholder="Driver's name" disabled>
</div>
</div>
</div>
@stop
答案 0 :(得分:0)
你应该可以这样做:
在AdminController.php中
$select_names = Walker::pluck('name', 'id')->toArray();
$walker = Walker::findOrFail($id);
return View::make('edit_request')->with($walker)->with($select_names);
在edit_request.blade.php
<div class="form-group">
{{ Form::label('Select Driver') }}
{{ Form::select('driver', $select_names, null, array('class'=>'form-control', 'placeholder'=>'Please select ...')) }}
</div>
您可以在https://laravelcollective.com/docs/master/html#form-model-binding
上阅读有关表单模型绑定和Laravel Collective的更多信息答案 1 :(得分:0)
您应该更新代码,如:
@extends('layout')
@section('content')
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title"><?= $title ?></h3>
</div><!-- /.box-header -->
<!-- form start -->
<form method="post" id="main-form" action="" enctype="multipart/form-data">
<input type="hidden" name="id" value="{{$walker->id}}">
<div class="box-body">
<div class="form-group">
<label>Driver's name</label>
<input type="text" class="form-control" name="first_name" value="{{$walker->first_name}}" placeholder="Driver's name" disabled>
</div>
</div>
</div>
@stop
public function edit_request($id){
$walker= DB::table('walker')->where('id',$id)->first();
return View::make('edit_request',compact('walker'));
}
希望这对你有用!