Earlier i was working on core php and currently i shift to laravel and mvc. So i dont know much about mvc and laravel too. I am facing one issue.Help me to solve this.
I have 2 tables:
- companies
- company_address
model for companies:
class Company extends Eloquent {
protected $fillable = [
'name',
'email',
'website',
'logo',
'phone',
];
protected $primaryKey = 'id';
protected $table = 'companies';
}
model for company_address:
class Companyaddress extends Eloquent {
protected $fillable = [
'companies_id',
'address_line_1',
'address_line_2',
'city',
'state',
'zipcode',
'country_id',
];
protected $primaryKey = 'id';
protected $table = 'company_address';
}
my controller to save this two tables:
public function store(CompanyRequest $request, Company $company, Companyaddress $companyaddress){
if(!Entrust::can('create-company'))
return response()->json(['message' => trans('messages.permission_denied'), 'status' => 'error']);
$data = $request->all();
$company->fill($data)->save();
$companyaddress->fill($data)->save();
storeCustomField($this->form,$company->id, $data);
$this->logActivity(['module' => 'company_address','module_id' => $company->id,'activity' => 'added']);
return response()->json(['message' => trans('messages.company').' '.trans('messages.added'), 'status' => 'success']);
}
My code works fine. on submit i can able to store data as per my models.
I want to store company
tables primary key in company_address
table as foreign key.so in future i can show address of particular company.
how to done it?