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) {

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

'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() }}
<input type="text" class="form-control" id="title" name="title">

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

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

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.