当我在Laravel中打开链接以创建 PDF 时,出现此错误:
语法错误,意外的'->'(T_OBJECT_OPERATOR)
以下是laravel突出显示的代码的代码段:
$customer_data = kunden::find($id);
->where('id', '=', $id)
->first();
我更改为: $ customer_data = kunden :: find($ id);
现在我收到此错误:
找不到类'MVS \ Http \ Controllers \ Kunden'
我在Http / Controllers中有一个控制器,名称为 KundenController
该控制器的内容为以下代码:
<?php
namespace MVS\Http\Controllers;
use MVS\Kunden;
use Illuminate\Http\Request;
class KundenController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$kunden = Kunden::all();
return view('admin.kunden.index', compact('kunden'));
}
/*
Funktion das nur eingeloggte Benutzer Kunden anlegen können
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.kunden.create'); }
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request,
[
'vorname' => 'required',
'nachname' => 'required',
'strasse' => 'required',
'plz' => 'required',
'wohnort' => 'required',
'mail' => 'required',
'telefon' => 'required',
'geburtsdatum' => 'required'
]
);
$kunden = new kunden();
$kunden->user_id = auth()->id();
$kunden->vorname = request('vorname');
$kunden->nachname = request('nachname');
$kunden->strasse = request('strasse');
$kunden->plz = request('plz');
$kunden->wohnort = request('wohnort');
$kunden->mail = request('mail');
$kunden->telefon = request('telefon');
$kunden->geburtsdatum = request('geburtsdatum');
$kunden->kaufpreis = request('kaufpreis');
$kunden->kostenumbau = request('kostenumbau');
$kunden->kostennotar = request('kostennotar');
$kunden->grunderwerbssteuer = request('grunderwerbssteuer');
$kunden->maklerkosten = request('maklerkosten');
$kunden->gesamtkosten = request('gesamtkosten');
$kunden->eigenkapital = request('eigenkapital');
$kunden->finanzierungsbedarf = request('finanzierungsbedarf');
$kunden->save();
return redirect('/admin/kunden');
}
/**
* Display the specified resource.
*
* @param \MVS\Kunden $kunden
* @return \Illuminate\Http\Response
*/
public function show(Kunden $kunden)
{
return view('admin.kunden.show', compact('kunden'));
}
/**
* Show the form for editing the specified resource.
*
* @param \MVS\Kunden $kunden
* @return \Illuminate\Http\Response
*/
public function edit(Kunden $kunden)
{
return view('admin.kunden.edit', compact('kunden'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \MVS\Kunden $kunden
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Kunden $kunden)
{
$this->validate($request,
[
'vorname' => 'required',
'nachname' => 'required',
'strasse' => 'required',
'plz' => 'required',
'wohnort' => 'required',
'mail' => 'required',
'telefon' => 'required',
'geburtsdatum' => 'required'
]
);
$kunden->vorname = request('vorname');
$kunden->nachname = request('nachname');
$kunden->strasse = request('strasse');
$kunden->plz = request('plz');
$kunden->wohnort = request('wohnort');
$kunden->mail = request('mail');
$kunden->telefon = request('telefon');
$kunden->geburtsdatum = request('geburtsdatum');
$kunden->kaufpreis = request('kaufpreis');
$kunden->kostenumbau = request('kostenumbau');
$kunden->kostennotar = request('kostennotar');
$kunden->grunderwerbssteuer = request('grunderwerbssteuer');
$kunden->maklerkosten = request('maklerkosten');
$kunden->gesamtkosten = request('gesamtkosten');
$kunden->eigenkapital = request('eigenkapital');
$kunden->finanzierungsbedarf = request('finanzierungsbedarf');
$kunden->save();
return redirect('/admin/kunden');
}
/**
* Remove the specified resource from storage.
*
* @param \MVS\Kunden $kunden
* @return \Illuminate\Http\Response
*/
public function destroy(Kunden $kunden)
{
$kunden->delete();
return back(); }
}
该应用的路线为:
Route::get('/', function () {
return view('welcome');
});
Route::get('/admin/kunden/pdf/{id}', 'DynamicPDFController@get_customer_data');
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('admin/kunden', 'KundenController');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/dynamic_pdf', 'DynamicPDFController@index');
Route::get('/dynamic_pdf/pdf', 'DynamicPDFController@pdf');
模型的路径是app / Kunden.php
内容是:
<?php
namespace MVS;
use Illuminate\Database\Eloquent\Model;
class Kunden extends Model
{
//
}
答案 0 :(得分:0)
更改为:
$customer_data = kunden::find($id);
答案 1 :(得分:0)
在您的控制器中
use App\Kunden; //kunden is your model
执行此操作
$customerData = Kunden::where('id', '=', $id)->first();
或
$customerData = kunden::find($id);