5 months ago

check input first

Posted 5 months ago by mada72

I have 2 tables: cities(id, name, postal_code) and addresses(id, street, city_id)

public function address(){

    return $this ->hasMany('App\Address');

In view/addresses/create. blade:

@extends('layouts.admin') @section('content')

<h1>Create Address</h1>

{!! Form::open(['method'=>'POST', 'action'=>'[email protected]','files'=>true]) !!}

<div class="form-group">
    {!! Form::label('street', 'Street:') !!}
    {!! Form::text('street', null, ['class'=>'form-control']) !!}

<div class="form-group">
    {!! Form::label('city_name', 'City:') !!}
    {!! Form::text('city_name',null, ['class'=>'form-control']) !!}
<div class="form-group">
    {!! Form::label('city_postal_code', 'Postal Code:') !!}
    {!! Form::text('city_postal_code' ,null, ['class'=>'form-control']) !!}
<div class="form-group">
    {!! Form::submit('Create Address', ['class'=>'btn btn-primary']) !!}
{!! Form::close() !!}


I want to create a new address but first I must check if my input(city) exist in my DB or create new input.

I don't know how I have to write this in controller:public function store

Please sign in or create an account to participate in this conversation.