php - Laravel 5.2 add Auth::id() to Posted data -


i started learn working laravel 5.2 framework 3 hours ago ^^

i did add task form , works made task_starter_id column in database

and data posted form task title , content input values

and question want add starter id auth::id(); can't it

i know old way post data in laravel 4

$task = new app\tasks();  // inputs $task->save(); 

but want laravel 5 way if it's possible

here's route.php

route::post('tasks', function(request $req) {      $data = $req::all();     $data['task_starter_id'] = auth::id();      $task = app\tasks::create($data);      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 explained want, all.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -