associate laravel
$account = App\Account::find(10);
$user->account()->associate($account);
$user->save();When updating a belongsTo relationship, you may use the associate method. This
method will set the foreign key on the child model:
$account = App\Account::find(10);
$user->account()->associate($account);
$user->save();
When removing a belongsTo relationship, you may use the dissociate method. This
method will set the relationship foreign key to null:
$user->account()->dissociate();
$user->save();//id for single
$user->reasons->attach($reasonId);
//array for multiple
$user->reasons->attach($reasonIds);
$user->save();<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
/**
* Get all of the deployments for the project.
*/
public function deployments()
{
return $this->hasManyThrough(Deployment::class, Environment::class);
}
}
Also in PHP:
- Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/
- add day for date php
- cache in redis by laravel
- empty laravel cache
- Woocommerce Display Custom Field value on the Email [Custom Field Display 3]
- find index of occurrence php
- PHP @ errors
- Class 'App\Http\Controllers\Session' not found
- client_ip() function php
- Woocommerce Display field value on the admin order edit page [Custom Field Display 2]
- Route::auth(); giving error in laravel 7
- ALTER table laravel
- Allowed memory size of 1610612736 bytes exhausted composer
- can i get mac id of laptop with php
- Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:
- cakephp send mail bcc
- date() options php
- convert php string to uppercase
- datetimepicker format php
- check if string contains substring php 8
- check if array offset exists php
- download laravel for php 5.6 windows
- check type of variable php
- !php.net date