dimanche 25 mars 2018

Adding an id based on another table, on create

Hi All I have a table in my database for friends

It goes like this

public function up()
    {
        Schema::create('tenancies', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->integer('friend_id');
            $table->string('property_address');
            $table->boolean('accepted')->default('0');;
            $table->timestamps();
        });
    }

I have a friend system in place that works, but I would like to add in another value when it is created. I have the methods and all implemented for adding, accepting, rejecting friends ect.

I have a create form, this has a user, friend, and property_Address columns

    <form action="/account//add" method="POST">
      
      <div class="row">
        <div class="col-md-6">
          <label for="property_address">Property Address</label>
        </div> <!-- ./col6 -->
      </div> <!-- ./ row-6 -->
      <div class="row">
        <div class="col-md-10">
          <select class="form-control" id="property_address" name="property_address">
            <!--Gets all counties from DB -->
            @foreach ($properties as $property)
              <option value=></option>
            @endforeach
          </select>
        </div> <!-- ./ col-6-->
      </div> <!-- ./ row-5  -->
      <div class="row mt-2">
        <div class="col-md-6">
          <label for="landlord-name">Landlord Name</label>
        </div> <!-- ./col=6 -->
      </div> <!-- ./ row-4-->
      <div class="row">
        <div class="col-md-6">
          <select class="form-control" name="landlord-name">
            <option value=""></option>
          </select>
        </div> <!-- ./ row 3-->
      </div> <!-- ./col-3 -->
      <div class="row mt-2">
        <div class="col-md-6">
          <label for="tenand-name">Tenant Name</label>
        </div> <!-- ./col=6 -->
      </div> <!-- ./ row-4-->
      <div class="row">
        <div class="col-md-6">
          <select class="form-control" name="tenant-name">
            <option value=""></option>
          </select>
        </div> <!-- ./ row 3-->
      </div> <!-- ./col-3 -->
      <button class="mt-2 btn btn-primary" type="submit">Create Tenancy</button>
    </form> <!-- ./form -->

When I created I want to add the selected address into the tenancies table above. The property comes from the properties table which is beneath

  public function up()
    {
        Schema::create('property_adverts', function (Blueprint $table) {
            $table->increments('id');
            $table->string("photo");
            $table->string('address');
            $table->integer('user_id');
            $table->timestamps();
        });
    }

How can I add the address field in the above table, to the property_address field at the beginning. So the relationship is user (landlord), tenancy_id (user), and property_address (the property chosen).

I have methods to add friend ect Should I post these also?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2DRKvCc
via IFTTT

Aucun commentaire:

Enregistrer un commentaire