mardi 5 avril 2016

Laravel 5.0: How to pass data to database table from html table

I am an absolute beginner of laravel. I am creating a project, but dealing with a certain problem.

I would like to pass data put on the table in the picture below to database table. The issue is that I don't have any idea how to put MULTIPLE data to one column. (As you can see below, the instructor will leave comments for both the first and the second row.)

I will eventually add a function that increases the number of rows.

This is what create.blade.php looks like enter image description here

English is not my first language so if this post does not make sense to you or you need more information, please leave your comments. Any advice would be appreciated. Thanks in advance!

Create.blade.php

@extends('log[![enter image description here][1]][1]s.app')

@section('content')

<style>
    table{border:solid 1px orange; border-spacing:0px; margin-bottom:16px;}
    th,td{border:solid 1px orange; padding:4px;}
    input[type='text']{width: 6em;}
</style>

<h1>Create a Log</h1>

<div id="wrapper">
    <table id="sampled1_table">
    <thead>
    <tr>
        <th>Weeks</th>
        <th>work_description</th>
        <th>instructor comments</th>
        <th>status</th></tr>
    </thead>

        {!! Form::open(['url' => 'journals']) !!}

        <tbody>
    <tr>
        <td class="weeks">
            {!! Form::selectRange('weeks[]', 1, 17) !!}
        </td>
        <td class="work_description">
            {!! Form::textarea('work_description[]', null) !!}
        </td>
        <td class="instructor_comments">
            {!! Form::textarea('instructor_comment[]', null) !!}
        </td>
        <td class="status">
            {!! Form::text('status[]', null) !!}

        </td>
    </tr>
    <tr>
        <td class="weeks">
            {!! Form::selectRange('weeks[]', 1, 17) !!}
        </td>
        <td class="work_description">
            {!! Form::textarea('work_description[]', null) !!}
        </td>
        <td class="instructor_comments">
            {!! Form::textarea('instructor_comment[]', null) !!}
        </td>
        <td class="status">
            {!! Form::text('status[]', null) !!}
        </td>
    </tr>
    <tbody>
</table>

</div>

<div class = "form-group">
    {!! Form::submit('create a Log', ['class' => 'btn btn-primary form-control']) !!}
</div>

{!! Form::close() !!}

@include('errors.lists')

@stop

Create_logs_table.php

public function up()
  {
    Schema::create('logs', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('weeks');
        $table->text('work_description');
        $table->text('instructor_comments');
        $table->string('status');
        $table->timestamps();

        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

    });
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire