Laravel Save Form Post

php artisan make:migration tasks

in database / migrations / create tasks table – paste in up()  function

Schema::create('tasks', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('body');
$table->timestamps();
});

php artisan make:model Task

in class Task extends Model

protected $guarded = [];

php artisan make:controller TasksController

in app / Http / Controllers / TaskController.php in the public function store(Request $request

Task::create([
'title' => request('title'),
'body' => request('body')
]);

return redirect('/');

Make blade template of form name ‘create.blade.php’

in resources / views/ make create.blade.php

<form method="post" action="/tasks">
{{ csrf_field() }}
Title
<input type="text" class="form-control" id="title" name="title">

Body
<textarea id="body" name="body" class="form-control">

<input type="submit" name="Submit" value="submit">
</form>

Add Routes for Post and Create in web.php

in routes / web.php

Route::post('/tasks', 'TasksController@store');

Route::get('/create', function() {
return view('create');
});

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *