nasirukun

bug relasi

Oct 6th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. -tabel user
  2. id
  3. name
  4. email
  5. pass
  6. role
  7.  
  8. -tabel client
  9. id
  10. client_name
  11. client_company
  12. adress
  13. email
  14. website
  15. users_id
  16.  
  17. -tabrl project
  18. id
  19. project_name
  20. project_detail
  21. project_type
  22. budget
  23. is_hour
  24. total_hour
  25. start_date
  26. end_date
  27. client_id
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. ////////model////////
  42. Proejct.php
  43. <?php
  44.  
  45. namespace App;
  46.  
  47. use Illuminate\Database\Eloquent\Model;
  48.  
  49.  
  50. class Project extends Model
  51. {
  52. protected $table = 'project';
  53.  
  54. public $timestamps = false;
  55.  
  56. protected $fillable = [
  57. 'name',
  58. 'client_id'
  59. ];
  60.  
  61. public function Client()
  62. {
  63. return $this->belongsTo('App\Clients');
  64. }
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. Clients.php
  76. <?php
  77.  
  78. namespace App;
  79.  
  80. use Illuminate\Database\Eloquent\Model;
  81.  
  82. class Clients extends Model
  83. {
  84. public $timestamps = false;
  85.  
  86. protected $table = 'client';
  87.  
  88. protected $fillable = [
  89. 'client_name',
  90. 'client_company',
  91. 'adress',
  92. 'email',
  93. 'website'
  94. ];
  95.  
  96. public function project()
  97. {
  98. return $this->hasMany('App\Project');
  99. }
  100.  
  101. public function user()
  102. {
  103. return $this->belongsTo('App\User');
  104. }
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. User.php
  118. <?php
  119.  
  120. namespace App;
  121.  
  122. use Illuminate\Foundation\Auth\User as Authenticatable;
  123.  
  124. class User extends Authenticatable
  125. {
  126.  
  127. protected $table = 'users';
  128. /**
  129. * The attributes that are mass assignable.
  130. *
  131. * @var array
  132.  
  133.  
  134. */
  135. protected $fillable = [
  136. 'name', 'email', 'password', 'role',
  137. ];
  138.  
  139. /**
  140. * The attributes that should be hidden for arrays.
  141. *
  142. * @var array
  143. */
  144. protected $hidden = [
  145. 'password', 'remember_token',
  146. ];
  147.  
  148. public function client()
  149. {
  150. return $this->hasOne('App\Clients');
  151. }
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. ProjectController
  165. <?php
  166.  
  167. namespace App\Http\Controllers;
  168.  
  169. use Illuminate\Http\Request;
  170.  
  171. use App\Http\Requests;
  172.  
  173. use App\Project;
  174.  
  175. use App\Clients;
  176.  
  177. use App\User;
  178.  
  179. class ProjectController extends Controller
  180. {
  181. public function index()
  182. {
  183. $Pr = Project::all();
  184. return view('project.index', ['project' => $Pr]);
  185. }
  186. }
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. buat nampilin nya
  203. foreach ($project as $projects) {
  204. <td>{{ $projects->client->users->name }}</td>
  205. }
Add Comment
Please, Sign In to add comment