I started to learn working with Laravel 5.2 framework about 3 hours ago ^^
I did add task form and it works but i made task_starter_id
column in database
and data that posted by form is only task title and content from input values
And finally my question is i want to add starter id with Auth::id();
i can't do it
I know the old way to post data in laravel 4
$task = new App\Tasks();
// inputs
$task->save();
But i want to do this with laravel 5 way if it's possible
Here's route.php
Route::post('tasks', function(Request $req) {
// return $req::all();
$task = App\Tasks::create($req::all());
return redirect('tasks');
});
Blade template :
<div class="panel-body">
{!! Form::open() !!}
<div class="form-group">
{!! Form::label('task_title', 'Task Title :') !!}
{!! Form::text('task_title', null,
array(
'class' => 'form-control',
'id' => 'task_title',
'placeholder' => 'Task Title'
)) !!}
</div>
<div class="form-group">
{!! Form::label('task_content', 'Task Content :') !!}
{!! Form::text('task_content', null,
array(
'class' => 'form-control',
'id' => 'task_content',
'placeholder' => 'Task Content'
)) !!}
</div>
{!! Form::submit('Add Task', ['class' => 'btn btn-primary btn-sm']) !!}
{!! Form::close() !!}
</div>
Model
class Tasks extends Model
{
protected $table = 'tasks';
protected $fillable = ['task_title','task_content','task_starter_id'];
}
I hope that i explained perfectly what i want, Thanks all.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire