NOVINKA! E-learningové kurzy umělé inteligence. Nyní AI za nejlepší ceny. Zjisti více:
NOVINKA – Víkendový online kurz Software tester, který tě posune dál. Zjisti, jak na to!

Diskuze: Duplikovane stlpce v databaze - Laravel

V předchozím kvízu, Online test znalostí PHP, jsme si ověřili nabyté zkušenosti z kurzu.

Aktivity
Avatar

Člen
Avatar
:25.7.2017 17:09

Caute, mam problem s vkladanim dat do datavazy cez laravel. Vzdy, ked vlozim do databazy data tak sa zdvoja.

Kod:

TodosController.php

<?php

namespace TCG\Voyager\Http\Controllers;

use Auth;
use App\Todo;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class TodosController extends Controller {

    public function store(Request $request) {

        $todo = new Todo;
        $todo -> TODO_Issue = $request['TODO_Issue'];
        $todo -> Description = $request['Description'];
        $todo -> Priority = $request['Priority'];
        $todo -> Time_Difficulty = $request['Time_Difficulty'];
        $todo -> Created_by = $request['Created_by'];
        $todo -> Difficulty = $request['Difficulty'];
        $todo -> save();

        return view('voyager::todos.index');
    }

}

Todo.php

class Todo extends Model
{

    protected $connection ='mysql';
    protected $table = 'todos';
    protected $primaryKey = 'id';

    protected $fillable = array('TODO_Issue', 'Description', 'Priority', 'Time_difficulty', 'Difficulty', 'Created_by');

    public $timestamps = true;

}

Form

<form class="form-edit-add" role="form"
                    action="{{ url('/admin/todo') }}"
                    method="POST" enctype="multipart/from-data">

                    {{ csrf_field() }}

                        <div class="panel-body">

                            <div class="form-group">
                                <label for="Created_by">Created by (user_id)</label>
                                <input type="text" class="form-control" value="{{ $id }}" name="Created_by" id="Created_by" readonly>
                            </div>

                            <div class="form-group">
                                <label for="TODO_Issue">TODO/Issue</label>
                                <input type="text" class="form-control" name="TODO_Issue" placeholder="TODO/Issue" id="TODO_Issue" required>
                            </div>

                            <div class="form-group">
                                <label for="Description">Description</label>
                                <textarea class="form-control textarea-resize" row="5" name="Description" id="Description" placeholder="Description" required></textarea>
                            </div>

                            <div class="form-group">
                                <label for="Priority">Priority (10 max)</label>
                                <select name="Priority" id="Priority" class="form-control">
                                    <option value="0">0</option>
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">8</option>
                                    <option value="9">9</option>
                                    <option value="10">10</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label for="Difficulty">Difficulty</label>
                                <select name="Difficulty" id="Difficulty" class="form-control">
                                    <option value="Low">Low</option>
                                    <option value="Medium">Medium</option>
                                    <option value="High">High</option>
                                    <option value="Highest">Highest</option>
                                </select>
                            </div

                            <div class="form-group">
                                <label for="TimeDifficulty">Time Difficulty (h)</label>
                                <input type="text" class="form-control" name="Time Difficulty" placeholder="Time Difficulty" id="TimeDifficulty" required>
                            </div>

                            <div class="panel-footer">
                                <button class="btn btn-primary" id="Add">Add TODO</button>
                            </div>

                        </div>

                    </form>

Dakujem za rady

 
Odpovědět
25.7.2017 17:09
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 1 zpráv z 1.