我正在使用laravel 5,我有一个更新/编辑表单,其中包含一个组合框。但我无法设置我的组合框值取决于数据库中的内容。你知道怎么做吗?
这是我的控制器:
public function ubahsurat(Request $request)
{
Surat::where('nomor_surat', '=', $request['nomor_surat'])->update(
['id_jenis_surat' => $request['id_jenis_surat']],
return redirect('/');
}
这是观点:
<div class="col-sm-9">
<select name="id_jenis_surat" class="form-control">
<option></option>
@foreach($jenis_surat as $js)
<option value="{{ $js->id_jenis_surat }}" > {{ $js->jenis_surat }} </option>
@endforeach
</select>
</div>
答案 0 :(得分:3)
您需要做的只是在有效的项目上设置selected="selected"
。
<option value="{{ $js->id_jenis_surat }}" {!! ($conditionForSelected ? "selected=\"selected\"" : "") !!}> {{ $js->jenis_surat }}</option>
将$conditionForSelected
替换为确定$js->id_jenis_surat
是否为所选当前项目的任何内容。
您的视图向我们展示了更新代码,而不是视图代码。
答案 1 :(得分:0)
你可以这样做:
@Configuration
@EnableBatchProcessing
public class BatchConfiguration{
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public MongoTemplate mongoTemplate;
@Autowired
UnitsRepository unitsRepos;
@Autowired
UserRepository userRepository;
@Autowired
ElectraService electraService;
/*@Autowired InfrastructureConfiguration infrastructureConfiguration;*/
// tag::readerwriterprocessor[]
@Bean
@StepScope
public MongoItemReader<UserBean> reader() {
MongoItemReader<UserBean> reader = new MongoItemReader<UserBean>();
reader.setTemplate(mongoTemplate);
reader.setCollection("user");
reader.setQuery("{ '_id': 'U3'}");
reader.setSort(new HashMap<String,Direction>(){{put("_id", Direction.ASC);}});
reader.setTargetType(UserBean.class);
return reader;
}
@Bean
public ExceedUsageProcessor processor() {
return new ExceedUsageProcessor(unitsRepos,electraService);
}
@Bean
public AnomalyProcessor anomalyProcessor() {
return new AnomalyProcessor(unitsRepos);
}
@Bean
@StepScope
public MongoItemWriter<DayByDayUsage> writer() {
MongoItemWriter<DayByDayUsage> writer = new MongoItemWriter<DayByDayUsage>();
writer.setTemplate(mongoTemplate);
writer.setCollection("usage");
return writer;
}
// end::readerwriterprocessor[]
// tag::listener[]
@Bean
@StepScope
public MongoItemWriter<AnomalyBean> anomalyWriter() {
MongoItemWriter<AnomalyBean> writer = new MongoItemWriter<AnomalyBean>();
writer.setTemplate(mongoTemplate);
writer.setCollection("anomaly");
return writer;
}
@Bean
public ExceedJobNotificationListener listener() {
return new ExceedJobNotificationListener(mongoTemplate);
}
@Bean
public AnomalyJobListener anomalyListener(){
return new AnomalyJobListener(mongoTemplate,userRepository);
}
// end::listener[]
// tag::jobstep[]
@Bean
public Job notifyUserJob() {
return jobBuilderFactory.get("notifyUserJob")
.incrementer(new RunIdIncrementer())
.listener(listener())
.flow(step1())
.end()
.build();
}
@Bean
public Job anomalyJob() {
return jobBuilderFactory.get("anomalyJob")
.incrementer(new RunIdIncrementer())
.listener(anomalyListener())
.flow(step2())
.end()
.build();
}
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.<UserBean, DayByDayUsage> chunk(50)
.reader(reader())
.processor(processor())
.writer(writer())
.taskExecutor(taskExecutor())
.throttleLimit(10)
.allowStartIfComplete(true)
.build();
}
// end::jobstep[]
@Bean
public Step step2() {
return stepBuilderFactory.get("step2")
.<UserBean, AnomalyBean> chunk(50)
.reader(reader())
.processor(anomalyProcessor())
.writer(anomalyWriter())
.taskExecutor(taskExecutor())
.throttleLimit(10)
.allowStartIfComplete(true)
.build();
}
@Bean
public TaskExecutor taskExecutor() {
// TODO Auto-generated method stub
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setMaxPoolSize(10);
taskExecutor.afterPropertiesSet();
return taskExecutor;
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.HSQL)
.addScript("classpath:/org/springframework/batch/core/schema-hsqldb.sql")
.build();
}
}
注意:我建议您使用Laravel Form Builders。所以你可以避免处理这些类型的问题。