[英]CRUD error in Laravel
Hello guys I made a CRUD(just create and read ) in Laravel project ,the create is working good and i passed the "loan" in show function but in the view it says undefined variable: 大家好,我在Laravel项目中创建了一个CRUD(只需创建并读取),创建工作正常,我在show函数中传递了“贷款”,但在视图中它显示了未定义的变量:
my show function in controller: 我在控制器中的显示功能:
public function show($id)
{
$loan=loan::find($id);
return view('finance/loans')->with('loan',$loan);
}
My routes: 我的路线:
Auth::routes();
Route::get('/loans', 'LoanController@viewLoanForm');
Route::post('/loans', 'LoanController@store');
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('loan','loanController');
Route::get('finance/loans', function () {
return view('loans');
});
And here is where i call the variable loan in the view: 这是我在视图中称为可变贷款的地方:
@extends('layouts.app')
@section('content')
<link href="{{ asset('css/loans.css') }}" rel="stylesheet">
<html>
<div class="container">
...
</div>
</div>
</div>
<div class="row">
<h1>{{$loan->nume}}</h1>//"nume"is the row from db i want to show
</div>
</div>
</html>
@endsection
You misspelled the route! 您拼错了路线! Your request does not reach the controller method 您的请求未达到控制器方法
Route::get('finance/loans', function () {
return view('loans');
});
should be so 应该是这样
Route::get('finance/loans/{$id}','loanController@show');
or should use the controller resource route 或应使用控制器资源路由
Route::resource('loans','loanController');
url 'loans/show/{$loan_id}' 网址“贷款/显示/ {$ loan_id}”
<a href="route('loans.show',[$id])">Show Loan</a>
your return should be like this: 您的回报应该是这样的:
return view('finance/loans')->with(['loan'=>$loan]);
instead of 代替
return view('finance/loans')->with('loan',$loan);
用这个 :
return view('finance.loans',compact(['loan']));
I think you need to on the route::resource('finance/loans') instead of ('loans'). 我认为您需要使用route :: resource('finance / loans')而不是('loans')。 And will work for sure 并且肯定会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.