Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel从联接表中给表单模型赋值_Php_Laravel_Jointable - Fatal编程技术网

Php Laravel从联接表中给表单模型赋值

Php Laravel从联接表中给表单模型赋值,php,laravel,jointable,Php,Laravel,Jointable,我有代码来获取数据并像这样连接两个表: $loan = Loan::findOrFail( $id ) ->join('customers', 'loans.customer_id', '=', 'customers.id') ->join('loans_detail','loans.id','=','loans_detail.loans_id') ->get(); return

我有代码来获取数据并像这样连接两个表:

 $loan = Loan::findOrFail( $id )
            ->join('customers', 'loans.customer_id', '=', 'customers.id')
            ->join('loans_detail','loans.id','=','loans_detail.loans_id')
            ->get();
            return view( 'loans.detail', compact( [ 'loan' ] ) );
然后我将该数据返回到:

{!! Form::model( $loan, [ 'method' => 'put' ] ) !!}
{!! Form::text( 'payment_type', null, [ 'class' => 'form-control'] ) !!}
但数据(付款类型)不显示。但是,如果删除连接代码,则会显示数据(付款类型)

若我对带有联接表的数据库使用dd()或不使用数据表,则会产生一些不同的结果

带联接表

Builder {#783 ▼
  #query: Builder {#782 ▶}
  #model: Loan {#779 ▶}
  #eagerLoad: []
  #localMacros: []
  #onDelete: null
  #passthru: array:12 [▶]
  #scopes: []
  #removedScopes: []
}
Loan {#779 ▼
  #table: "loans"
  #guarded: []
  #connection: "pgsql"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:9 [▶]
  #original: array:9 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
}
不带外联接表

Builder {#783 ▼
  #query: Builder {#782 ▶}
  #model: Loan {#779 ▶}
  #eagerLoad: []
  #localMacros: []
  #onDelete: null
  #passthru: array:12 [▶]
  #scopes: []
  #removedScopes: []
}
Loan {#779 ▼
  #table: "loans"
  #guarded: []
  #connection: "pgsql"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:9 [▶]
  #original: array:9 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
}
findOrFail()
已执行查询,之后调用
join()
启动新查询

试试这个:

$loan = Loan::whereKey($id)
    ->join('customers', 'loans.customer_id', '=', 'customers.id')
    ->join('loans_detail','loans.id','=','loans_detail.loans_id')
    ->first();
顺便说一句:这种查询应该使用Relationships:

findOrFail()
已执行查询,之后调用
join()
启动新查询

试试这个:

$loan = Loan::whereKey($id)
    ->join('customers', 'loans.customer_id', '=', 'customers.id')
    ->join('loans_detail','loans.id','=','loans_detail.loans_id')
    ->first();
顺便说一句:这种查询应该使用Relationships: