我有一个小型 CRM 系统。我可以创建、更新和删除客户。我也有每个客户的详细 View 。现在我想在单个 View 的末尾有一个按钮:Create Offer。
我有 2 个表。 1 表有名称:客户有一些字段姓名、姓氏等。我这样创建客户:
<form method="post" action="/mvs/mvs/public/admin/kunden">
{{ csrf_field() }}
<div class="container">
<div class="row">
<div class="col-md-12 col-md-offset-2" >
<div class="form-group">
<label for="vorname">Vorname</label>
<input type="text" class="form-control" name="vorname" id="vorname" placeholder="Vorname" value="{{ old('vorname') }}" required>
</div>
<div class="form-group">
<label for="nachname">Nachname</label>
<input type="text" class="form-control" name="nachname" id="nachname" placeholder="Nachname" value="{{ old('nachname') }}" required>
</div>
<div class="form-group">
<label for="strasse">Straße</label>
<input type="text" class="form-control" name="strasse" id="strasse" placeholder="Strasse" value="{{ old('strasse') }}" required>
</div>
<div class="form-group">
<label for="plz">PLZ</label>
<input type="number" class="form-control" name="plz" id="plz" placeholder="Plz" value="{{ old('plz') }}" required>
</div>
<div class="form-group">
<label for="wohnort">Wohnort</label>
<input type="text" class="form-control" name="wohnort" id="wohnort" placeholder="Wohnort" value="{{ old('wohnort') }}" required>
</div>
<div class="form-group">
<label for="mail">Mail</label>
<input type="mail" class="form-control" name="mail" id="mail" placeholder="E-mail" value="{{ old('mail') }}" required>
</div>
<div class="form-group">
<label for="telefon">Telefon</label>
<input type="text" class="form-control" name="telefon" id="telefon" placeholder="Telefon" value="{{ old('telefon') }}" required>
</div>
<div class="form-group">
<label for="geburtsdatum">Geburtsdatum</label>
<input type="date" class="form-control" name="geburtsdatum" id="geburtsdatum" placeholder="Geburtsdatum" value="{{ old('geburtsdatum') }}" required>
</div>
<br>
<button type="submit" class="btn btn-primary">Kunden anlegen</button>
<a href="{{ URL::previous() }}"><button type="submit" class="btn btn-danger">Abbrechen</button></a>
</div>
</div>
</div>
</form>
详细 View 与该页面类似。在详细 View 中,我制作了一个按钮。该按钮链接到动态 PDF Controller 。动态 PDF Controller 可以工作,但我不知道如何从详细 View 客户那里获取数据。我只从表中的所有客户那里获取数据。
这是片段:
function get_customer_data()
{
$customer_data = DB::table('kundens')
->limit(10)
->get();
return $customer_data;
}
我知道这是错误的(我是新手,对此感到抱歉) 但我不知道如何编写代码,从详细 View 中选择的客户那里获取数据。
当我点击按钮时,我希望 PDF 保存在数据库中并链接到该客户。
我希望我解释清楚了。如果不满意,请不要低估 - 我会在还不够的时候尝试更好地解释。
最佳答案
如果我理解正确的话: 您只想在点击按钮时从一个特定的客户那里获取数据?
带有 kunden id 的按钮链接:
<a href="/mvs/mvs/public/admin/kunden/pdf/{{ $kunden->id }}">Button html</a>
新路线:
Route::get('/mvs/mvs/public/admin/kunden/pdf/{id}', ControllerName@get_customer_data');
Controller 更新:
function get_customer_data($id)
{
//Handle PDF stuff here
$customer_data = DB::table('kundens')
->where('id', '=', $id)
->firstOrFail();
//Save PDF link to customer here
$customer_data->save();
return $customer_data;
}
---- 编辑 ----
完整指南:
HTML:
<form method="post" action="/mvs/mvs/public/admin/kunden/pdf/{{ $kunden->id }}">
{{ csrf_field() }}
<div class="container">
<div class="row">
<div class="col-md-12 col-md-offset-2" >
<div class="form-group">
<label for="vorname">Vorname</label>
<input type="text" class="form-control" name="vorname" id="vorname" placeholder="Vorname" value="{{ old('vorname') }}" required>
</div>
<div class="form-group">
<label for="nachname">Nachname</label>
<input type="text" class="form-control" name="nachname" id="nachname" placeholder="Nachname" value="{{ old('nachname') }}" required>
</div>
<div class="form-group">
<label for="strasse">Straße</label>
<input type="text" class="form-control" name="strasse" id="strasse" placeholder="Strasse" value="{{ old('strasse') }}" required>
</div>
<div class="form-group">
<label for="plz">PLZ</label>
<input type="number" class="form-control" name="plz" id="plz" placeholder="Plz" value="{{ old('plz') }}" required>
</div>
<div class="form-group">
<label for="wohnort">Wohnort</label>
<input type="text" class="form-control" name="wohnort" id="wohnort" placeholder="Wohnort" value="{{ old('wohnort') }}" required>
</div>
<div class="form-group">
<label for="mail">Mail</label>
<input type="mail" class="form-control" name="mail" id="mail" placeholder="E-mail" value="{{ old('mail') }}" required>
</div>
<div class="form-group">
<label for="telefon">Telefon</label>
<input type="text" class="form-control" name="telefon" id="telefon" placeholder="Telefon" value="{{ old('telefon') }}" required>
</div>
<div class="form-group">
<label for="geburtsdatum">Geburtsdatum</label>
<input type="date" class="form-control" name="geburtsdatum" id="geburtsdatum" placeholder="Geburtsdatum" value="{{ old('geburtsdatum') }}" required>
</div>
<br>
<input type="hidden" name="kunden-id" value="{{ $kunden->id }}" />
<button type="submit" class="btn btn-primary" >Kunden anlegen</button>
<a href="{{ URL::previous() }}"><button type="submit" class="btn btn-danger">Abbrechen</button></a>
</div>
</div>
</div>
</form>
路线:
Route::get('/mvs/mvs/public/admin/kunden/pdf/{id}', DynamicPDFController@index');
Controller :
namespace MVS\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use PDF;
use MVS\Kunden;
class DynamicPDFController extends Controller
{
function index(Request $request)
{
$data = $request->all();
$id = $data['kunden-id'];
$customer_data = $this->get_customer_data($id);
//$finance_data = $this->get_finance_data();
return view('dynamic_pdf')->with('customer_data', $customer_data);
}
function get_customer_data($id)
{
$customer_data = Kunden::whereId($id)->first();
return $customer_data;
}
function pdf()
{
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML($this->convert_customer_data_to_html());
return $pdf->stream();
}
function convert_customer_data_to_html()
{
$customer_data = $this->get_customer_data();
$output = '
<h3 align="center">Angebot</h3>
<table width="100%" style="border-collapse: collapse; border: 0px;">
<tr>
<th style="border: 1px solid; padding:12px;" width="20%">Vorname</th>
<th style="border: 1px solid; padding:12px;" width="30%">Nachname</th>
<th style="border: 1px solid; padding:12px;" width="15%">Stadt</th>
<th style="border: 1px solid; padding:12px;" width="15%">PLZ</th>
</tr>
';
foreach($customer_data as $kunden)
{
$output .= '
<tr>
<td style="border: 1px solid; padding:12px;">'.$kunden->vorname.'</td>
<td style="border: 1px solid; padding:12px;">'.$kunden->nachname.'</td>
<td style="border: 1px solid; padding:12px;">'.$kunden->wohnort.'</td>
<td style="border: 1px solid; padding:12px;">'.$kunden->plz.'</td>
</tr>
';
}
$output .= '</table>';
return $output;
}
}
关于php - 向客户添加 PDF - laravel 5.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52833648/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我需要一个表,其中行实际上是2行表,一个嵌套表是..我怎样才能在Prawn中做到这一点?也许我需要延期..但哪一个? 最佳答案 现在支持子表:Prawn::Document.generate("subtable.pdf")do|pdf|subtable=pdf.make_table([["sub"],["table"]])pdf.table([[subtable,"original"]])end 关于ruby-on-rails-PrawnPDF:Ineedtogeneratenested
当谈到运行时自省(introspection)和动态代码生成时,我认为ruby没有任何竞争对手,可能除了一些lisp方言。前几天,我正在做一些代码练习来探索ruby的动态功能,我开始想知道如何向现有对象添加方法。以下是我能想到的3种方法:obj=Object.new#addamethoddirectlydefobj.new_method...end#addamethodindirectlywiththesingletonclassclass这只是冰山一角,因为我还没有探索instance_eval、module_eval和define_method的各种组合。是否有在线/离线资
我注意到类定义,如果我打开classMyClass,并在不覆盖的情况下添加一些东西我仍然得到了之前定义的原始方法。添加的新语句扩充了现有语句。但是对于方法定义,我仍然想要与类定义相同的行为,但是当我打开defmy_method时似乎,def中的现有语句和end被覆盖了,我需要重写一遍。那么有什么方法可以使方法定义的行为与定义相同,类似于super,但不一定是子类? 最佳答案 我想您正在寻找alias_method:classAalias_method:old_func,:funcdeffuncold_func#similartoca
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
我正在开发一个创建网络博客的RubyonRails项目。我希望将一个名为featured的boolean数据库字段添加到Post模型中。该字段应该可以通过我添加的事件管理界面进行编辑。我使用了以下代码,但我什至没有在网站上显示另一列。$railsgeneratemigrationaddFeaturedfeatured:boolean$rakedb:migrate我是RubyonRails的新手,非常感谢任何帮助。我的index.html.erb文件中的相关代码(views):FeaturedPost架构.rb:ActiveRecord::Schema.define(:version=>
假设我有一个这样的单例类:classSettingsincludeSingletondeftimeout#lazy-loadtimeoutfromconfigfile,orwhateverendend现在,如果我想知道使用什么超时,我需要编写如下内容:Settings.instance.timeout但我宁愿将其缩短为Settings.timeout使这项工作有效的一个明显方法是将设置的实现修改为:classSettingsincludeSingletondefself.timeoutinstance.timeoutenddeftimeout#lazy-loadtimeoutfromc