Apr 11, 2019
0
Level 2
updateOrCreate for 3 tables
I have 3 tables;countries(id, name), cities(id, name, postal_code, country_id) and addresses(id, street,city_id) in view/addresses/edit.blade: ...
@extends('layouts.admin') @section('content')
Addresses
{!! Form::model($address,['method'=>'PATCH', 'action'=>['AdminAddressesController@update', $address->id], 'files'=>true]) !!} {!! Form::label('street', 'Street:') !!} {!! Form::text('street', null, ['class'=>'form-control']) !!} {!! Form::label('city_name', 'City:') !!} {!! Form::text('city_name',$address->city->name, null, ['class'=>'form-control']) !!} {!! Form::label('city_postal_code', 'Postal Code:') !!} {!! Form::text('city_postal_code',$address->city->postal_code, null, ['class'=>'form-control']) !!} {!! Form::label('country_name', 'Country:') !!} {!! Form::text('country_name', $address->city->country->name, null, ['class'=>'form-control']) !!} {!! Form::submit('Update Address', ['class'=>'btn btn-primary']) !!} {!! Form::close() !!}{!! Form::open(['method'=>'DELETE', 'action'=>['AdminAddressesController@destroy', $address->id],
'files'=>true])
!!}
<div class="form-group">
{!! Form::submit('Delete Address', ['class'=>'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
...
how can use updateOrCreate? ex. I want to change 'country_name' in address -if a country exist -update address, if not -create a new country and update address
Please or to participate in this conversation.