【发布时间】:2017-04-28 02:00:44
【问题描述】:
我的控制器是这样的:
<?php
namespace App\Http\Controllers;
...
class UserController extends AppBaseController
{
/** @var UserRepository */
private $userRepository;
public function __construct(UserRepository $userRepo)
{
$this->userRepository = $userRepo;
}
public function index(Request $request)
{
$this->userRepository->pushCriteria(new RequestCriteria($request));
$users = $this->userRepository->all();
return view('users.index')
->with('users', $users);
}
}
..
我的仓库是这样的:
<?php
namespace App\Repositories;
use App\Models\User;
use InfyOm\Generator\Common\BaseRepository;
class UserRepository extends BaseRepository
{
protected $fieldSearchable = [
'username',
'email',
'password',
'kdkotama',
'kdsatker',
'nama_lengkap',
'telp',
'level',
'kdtingkat'
];
public function model()
{
return User::class;
}
}
我的模型是这样的:
<?php
namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model
{
use SoftDeletes;
public $table = 'users';
protected $dates = ['deleted_at'];
public $fillable = [
'username',
'email',
'password',
'kdkotama',
'kdsatker',
'nama_lengkap',
'telp',
'level',
'kdtingkat'
];
protected $casts = [
'username' => 'string',
'email' => 'string',
'password' => 'string',
'kdkotama' => 'string',
'kdsatker' => 'string',
'nama_lengkap' => 'string',
'telp' => 'string',
'level' => 'string',
'kdtingkat' => 'string'
];
}
我的看法是这样的:
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1 class="pull-left">Users</h1>
<h1 class="pull-right">
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('users.create') !!}">Add New</a>
</h1>
</section>
<div class="content">
<div class="clearfix"></div>
@include('flash::message')
<div class="clearfix"></div>
<div class="box box-primary">
<div class="box-body">
@include('users.table')
</div>
</div>
</div>
@endsection
<table class="table table-responsive" id="users-table">
<thead>
<th>No</th>
<th>Username</th>
<th>Email</th>
<th>Kotama</th>
<th>Satker</th>
<th>Nama Lengkap</th>
<th>Telp / No HP</th>
<th>Level</th>
<th>Tingkat</th>
<th colspan="3">Action</th>
</thead>
<tbody>
@foreach($users as $key => $user)
<tr>
<td>{!! ++$key !!}</td>
<td>{!! $user->username !!}</td>
<td>{!! $user->email !!}</td>
<td>{!! $user->kdkotama !!}</td>
<td>{!! $user->kdsatker !!}</td>
<td>{!! $user->nama_lengkap !!}</td>
<td>{!! $user->telp !!}</td>
<td>{!! $user->level !!}</td>
<td>{!! $user->kdtingkat !!}</td>
<td>
{!! Form::open(['route' => ['users.destroy', $user->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('users.edit', [$user->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
我的模型取自表 users。我想加入另一张桌子。 kdkotama 字段和 kdsatker 字段如:kotama 代码和 satker 代码。我想加入表 t_kotams 和表 t_satkers 以获得 kotama 名称和 satker 名称。
使用 infyom laravel 生成器,我很困惑,如何实现。有没有人可以帮助我?
Laravel infyom 生成器源码:
【问题讨论】:
-
没有人能回答这个问题吗?这个问题有那么难吗?
-
不,不是那样,但很少有人在他们的项目中使用这个管理面板工具
-
我同意 Niket Joshi,我正在寻找一种方法来使用所有视图和生成的东西更新现有模型......但似乎很困难
标签: php mysql laravel generator laravel-5.3