Die*_*ick 5 php mysql laravel laravel-5
我有一个小型CRM系统.我可以创建,更新和删除客户.我还为每位客户提供了详细的视图.现在我想在单个视图的最后一个按钮:Create Offer.
我有2张桌子.1表有名称:customer with some fields Name,Surname等我创建了这样的客户:
<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>
Run Code Online (Sandbox Code Playgroud)
详细视图与该页面类似.在详细视图中,我做了一个按钮.该按钮链接到动态PDF控制器.动态PDF控制器工作但我不知道如何从详细视图客户获取数据.我只从表中的所有客户那里获得数据.
这是片段:
function get_customer_data()
{
$customer_data = DB::table('kundens')
->limit(10)
->get();
return $customer_data;
}
Run Code Online (Sandbox Code Playgroud)
我明白这是错误的(我初学者很抱歉)但我不知道如何编码,我从客户那里得到了我在详细视图中所记录的数据.
当我点击按钮时,我希望PDF保存在数据库中并链接到该客户.
我希望我解释清楚.什么时候不请不要低估 - 当它不够时,我试着更好地解释.
如果我理解正确的话:\n您只想在单击按钮时从一位特定客户处获取数据?
\n\n带有 kunden id 的按钮链接:
\n\n<a href="/mvs/mvs/public/admin/kunden/pdf/{{ $kunden->id }}">Button html</a>\nRun Code Online (Sandbox Code Playgroud)\n\n新路线:
\n\nRoute::get(\'/mvs/mvs/public/admin/kunden/pdf/{id}\', ControllerName@get_customer_data\');\nRun Code Online (Sandbox Code Playgroud)\n\n控制器更新:
\n\nfunction get_customer_data($id)\n{\n //Handle PDF stuff here \n\n $customer_data = DB::table(\'kundens\')\n ->where(\'id\', \'=\', $id)\n ->firstOrFail();\n\n//Save PDF link to customer here\n\n $customer_data->save();\n return $customer_data;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n- -编辑- -
\n\n完整指南:
\n\nHTML:
\n\n<form method="post" action="/mvs/mvs/public/admin/kunden/pdf/{{ $kunden->id }}">\n {{ csrf_field() }}\n <div class="container">\n <div class="row">\n <div class="col-md-12 col-md-offset-2" >\n\n <div class="form-group">\n <label for="vorname">Vorname</label>\n <input type="text" class="form-control" name="vorname" id="vorname" placeholder="Vorname" value="{{ old(\'vorname\') }}" required>\n </div>\n <div class="form-group">\n <label for="nachname">Nachname</label>\n <input type="text" class="form-control" name="nachname" id="nachname" placeholder="Nachname" value="{{ old(\'nachname\') }}" required>\n </div>\n\n <div class="form-group">\n <label for="strasse">Stra\xc3\x9fe</label>\n <input type="text" class="form-control" name="strasse" id="strasse" placeholder="Strasse" value="{{ old(\'strasse\') }}" required>\n </div>\n\n <div class="form-group">\n <label for="plz">PLZ</label>\n <input type="number" class="form-control" name="plz" id="plz" placeholder="Plz" value="{{ old(\'plz\') }}" required>\n </div>\n\n <div class="form-group">\n <label for="wohnort">Wohnort</label>\n <input type="text" class="form-control" name="wohnort" id="wohnort" placeholder="Wohnort" value="{{ old(\'wohnort\') }}" required>\n </div>\n\n <div class="form-group">\n <label for="mail">Mail</label>\n <input type="mail" class="form-control" name="mail" id="mail" placeholder="E-mail" value="{{ old(\'mail\') }}" required>\n </div>\n\n <div class="form-group">\n <label for="telefon">Telefon</label>\n <input type="text" class="form-control" name="telefon" id="telefon" placeholder="Telefon" value="{{ old(\'telefon\') }}" required>\n </div>\n\n <div class="form-group">\n <label for="geburtsdatum">Geburtsdatum</label>\n <input type="date" class="form-control" name="geburtsdatum" id="geburtsdatum" placeholder="Geburtsdatum" value="{{ old(\'geburtsdatum\') }}" required>\n </div>\n\n <br>\n<input type="hidden" name="kunden-id" value="{{ $kunden->id }}" />\n <button type="submit" class="btn btn-primary" >Kunden anlegen</button>\n\n <a href="{{ URL::previous() }}"><button type="submit" class="btn btn-danger">Abbrechen</button></a>\n\n </div>\n </div>\n </div>\n</form>\nRun Code Online (Sandbox Code Playgroud)\n\n路线:
\n\nRoute::get(\'/mvs/mvs/public/admin/kunden/pdf/{id}\', DynamicPDFController@index\');\nRun Code Online (Sandbox Code Playgroud)\n\n控制器:
\n\nnamespace MVS\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse DB;\nuse PDF;\nuse MVS\\Kunden;\n\nclass DynamicPDFController extends Controller\n{\n function index(Request $request)\n {\n\n $data = $request->all();\n\n $id = $data[\'kunden-id\'];\n $customer_data = $this->get_customer_data($id);\n //$finance_data = $this->get_finance_data();\n return view(\'dynamic_pdf\')->with(\'customer_data\', $customer_data);\n }\n\n function get_customer_data($id)\n {\n $customer_data = Kunden::whereId($id)->first();\n return $customer_data;\n }\n\n function pdf()\n {\n $pdf = \\App::make(\'dompdf.wrapper\');\n $pdf->loadHTML($this->convert_customer_data_to_html());\n return $pdf->stream();\n }\n\n function convert_customer_data_to_html()\n {\n $customer_data = $this->get_customer_data();\n $output = \'\n <h3 align="center">Angebot</h3>\n <table width="100%" style="border-collapse: collapse; border: 0px;">\n <tr>\n <th style="border: 1px solid; padding:12px;" width="20%">Vorname</th>\n <th style="border: 1px solid; padding:12px;" width="30%">Nachname</th>\n <th style="border: 1px solid; padding:12px;" width="15%">Stadt</th>\n <th style="border: 1px solid; padding:12px;" width="15%">PLZ</th>\n </tr>\n \'; \n foreach($customer_data as $kunden)\n {\n $output .= \'\n <tr>\n <td style="border: 1px solid; padding:12px;">\'.$kunden->vorname.\'</td>\n <td style="border: 1px solid; padding:12px;">\'.$kunden->nachname.\'</td>\n <td style="border: 1px solid; padding:12px;">\'.$kunden->wohnort.\'</td>\n <td style="border: 1px solid; padding:12px;">\'.$kunden->plz.\'</td>\n </tr>\n \';\n }\n $output .= \'</table>\';\n return $output;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n