Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /*
  2. echo '<br>---------show single company from user---------------<br>';
  3.  
  4. $user = \App\User::find(6);
  5.  
  6. if ($user) {
  7.  
  8. $company = $user->company->name;
  9. echo $company;
  10.  
  11. }
  12. else {
  13. echo 'cannot find data';
  14. }
  15. */
  16.  
  17. /*
  18. echo '<br>----------show single user from company --------------<br>';
  19.  
  20. $company = \App\Company::find(5);
  21.  
  22. if ($company) {
  23. echo $company->user->name;
  24. }
  25. else {
  26. echo 'cannot find company';
  27. }
  28. */
  29.  
  30.  
  31. /*
  32. echo '<br>--------- saving data using relationship---------------<br>';
  33.  
  34. static $password;
  35.  
  36. $data = [
  37. 'name' => $faker->name,
  38. 'email' => $faker->unique()->safeEmail,
  39. 'password' => $password ?: $password = bcrypt('secret'),
  40. 'remember_token' => str_random(10),
  41. ];
  42.  
  43. $newUser = \App\User::create($data);
  44.  
  45. if ($newUser) {
  46.  
  47. $newUser->company()->create(['name' => $faker->company]);
  48.  
  49. echo $newUser->company->name;
  50. }
  51. else {
  52. echo 'something went wrong';
  53. }
  54. */
  55.  
  56.  
  57. /*
  58. echo '<br>--------- belongsTo associate function---------------<br>';
  59. $sampleUser = \App\User::find(6);
  60. $sampleCompany = \App\Company::find(10);
  61. $sampleCompany->user()->associate($sampleUser);
  62. $sampleCompany->save();
  63. */
  64.  
  65.  
  66. /*
  67. echo '<br>----------updating parent using child id --------------<br>';
  68.  
  69. $company = \App\Company::find(5);
  70.  
  71. $company->user->name = 'mickey mouse';
  72. $company->user->save();
  73. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement