Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- echo '<br>---------show single company from user---------------<br>';
- $user = \App\User::find(6);
- if ($user) {
- $company = $user->company->name;
- echo $company;
- }
- else {
- echo 'cannot find data';
- }
- */
- /*
- echo '<br>----------show single user from company --------------<br>';
- $company = \App\Company::find(5);
- if ($company) {
- echo $company->user->name;
- }
- else {
- echo 'cannot find company';
- }
- */
- /*
- echo '<br>--------- saving data using relationship---------------<br>';
- static $password;
- $data = [
- 'name' => $faker->name,
- 'email' => $faker->unique()->safeEmail,
- 'password' => $password ?: $password = bcrypt('secret'),
- 'remember_token' => str_random(10),
- ];
- $newUser = \App\User::create($data);
- if ($newUser) {
- $newUser->company()->create(['name' => $faker->company]);
- echo $newUser->company->name;
- }
- else {
- echo 'something went wrong';
- }
- */
- /*
- echo '<br>--------- belongsTo associate function---------------<br>';
- $sampleUser = \App\User::find(6);
- $sampleCompany = \App\Company::find(10);
- $sampleCompany->user()->associate($sampleUser);
- $sampleCompany->save();
- */
- /*
- echo '<br>----------updating parent using child id --------------<br>';
- $company = \App\Company::find(5);
- $company->user->name = 'mickey mouse';
- $company->user->save();
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement